$query = "select count[*]
from relationships
where leader = 'user_id'";
$result = mysql_query[$query];
Làm thế nào tôi có thể hiển thị số lượng? cảm ơn
Hỏi ngày 25 tháng 9 năm 2010 lúc 13:48Sep 25, 2010 at 13:48
1
$count = mysql_fetch_array[$result];
echo $count[0];
Đã trả lời ngày 25 tháng 9 năm 2010 lúc 13:50Sep 25, 2010 at 13:50
MischamischaMischa
42.5K8 Huy hiệu vàng98 Huy hiệu bạc111 Huy hiệu đồng8 gold badges98 silver badges111 bronze badges
$query = "SELECT COUNT[*] AS total FROM table"; $result = mysql_query[$query]; $values = mysql_fetch_assoc[$result]; $num_rows = $values['total']; echo $num_rows;
Đã trả lời ngày 25 tháng 9 năm 2010 lúc 13:51Sep 25, 2010 at 13:51
Sushil Bharwanisushil Bharwanisushil bharwani
29.2k30 Huy hiệu vàng92 Huy hiệu bạc128 Huy hiệu đồng30 gold badges92 silver badges128 bronze badges
- Sử dụng
$row = mysql_fetch_array[$result]
và truy cập nó theo chỉ mục 0: $ row [0] - Sử dụng bí danh trong truy vấn của bạn ["Chọn đếm [*] làm CNT từ ..."] và
$row = mysql_fetch_assoc[$result]
và truy cập nó theo tên: $ row ['cnt']]
Đã trả lời ngày 25 tháng 9 năm 2010 lúc 13:51Sep 25, 2010 at 13:51
hacksteak25hacksteak25hacksteak25
Sushil Bharwanisushil Bharwani1 gold badge15 silver badges23 bronze badges
$abc="SELECT count[*] as c FROM output WHERE question1=4";
$result=mysqli_query[$conn,$abc];
if[$result]
{
while[$row=mysqli_fetch_assoc[$result]]
{
echo $row['c'];
}
}
29.2k30 Huy hiệu vàng92 Huy hiệu bạc128 Huy hiệu đồng
Sử dụng $row = mysql_fetch_array[$result]
và truy cập nó theo chỉ mục 0: $ row [0]Jun 29, 2017 at
2:38
2
Có: //php.net/manual/en/function.mysql-petch-array.php Ví dụ #2 mysql_fetch_array [] với mysql_num Mã số: Lưu ý phần in đậm trong mã. Mã số:SELECT `tkid`,COUNT[*] FROM `xd2e_trooptrack_attendee` WHERE `costumeid` 20 AND `costumeid` 21 AND `costumeid` 31 GROUP BY `tkid`
I'm trying to write a PHP page to display this same data, and I'm not having any luck. Here is what I have so far:$troopcount_sql = 'SELECT `tkid`,COUNT[*] FROM `xd2e_trooptrack_attendee` WHERE `costumeid` 20 AND `costumeid` 21 AND `costumeid` 31 GROUP BY `tkid`';
$troopcount_result = mysql_query[$troopcount_sql];
?>
TKID
Troop Count
Lưu ý phần in đậm trong mã.
What am I missing? Thank you all in advance!
- Thêm dấu trang
- #6
Có: //php.net/manual/en/function.mysql-petch-array.php Ví dụ #2 mysql_fetch_array [] với mysql_num Mã số:SELECT 'tkid', COUNT[*] AS "COUNT"
FROM 'xd2e_trooptrack_attendee'
WHERE 'costumeid' NOT IN [20, 21, 30]
GROUP BY 'tkid'
Lưu ý phần in đậm trong mã.
- Thêm dấu trang
- #6
Có: //php.net/manual/en/function.mysql-petch-array.php Ví dụ #2 mysql_fetch_array [] với mysql_num
I will try it with your syntax and
see if it changes my results.
Thank you!
- Thêm dấu trang
- #6
Có: //php.net/manual/en/function.mysql-petch-array.php Ví dụ #2 mysql_fetch_array [] với mysql_num
- Thêm dấu trang
- #6
Có: //php.net/manual/en/function.mysql-petch-array.php Ví dụ #2 mysql_fetch_array [] với mysql_num . DarkskyForever [/url] ": 2ChM2H44] Đề xuất tạo bọt nên 'sửa' vấn đề. Bạn đang thực hiện một cột tổng hợp nhưng không gán nó một bí danh. Bạn có thể truy cập nó theo chỉ mục [kết quả [0], kết quả [1]], hoặc gán nó một tên và truy cập nó theo cách đó.
var_dump[$troopcount_row];
var_dump shows you everything in the object or array. That'll let you get the index of the value you want, so you can feed it to your echo statement.
//secure.php.net/manual/en/function.var-dump.php
I don't know what you're up to, but your approach is fine if it's hard-coded. As soon as you want to let someone search for something via a search box on your website, you need to look at prepared statements via PDO:
//secure.php.net/manual/en/pdo.pr ... ements.php
This will protect you against someone malicious sending you bad SQL queries as "search" parameters. This is called a SQL injection attack:
//www.troyhunt.com/everything-you ...
about-sql/
Tôi không tin PHP sẽ cho phép bạn truy cập một mảng trong biểu mẫu: "foo" => "Bar" 100 => "Bat" bằng cách sử dụng lập chỉ mục dựa trên không [[0] => "Bar"], phải không?
"foo" => "bar"
100 => "bat"
by using zero-based indexing [[0] => "bar"], will it?
- Thêm dấu trang
- #6
Có: //php.net/manual/en/function.mysql-petch-array.php Ví dụ #2 mysql_fetch_array [] với mysql_num Đã trả lời ngày 29 tháng 6 năm 2017 lúc 2:38 Lưu ý phần in đậm trong mã.
Example #2 mysql_fetch_array[] with MYSQL_NUM
mysql_connect["localhost", "mysql_user", "mysql_password"]
or
die["Could not connect: " . mysql_error[]];
mysql_select_db["mydb"];
$result = mysql_query["SELECT id, name FROM mytable"];
while [$row = mysql_fetch_array[$result, MYSQL_NUM]] {
printf["ID: %s Name: %s", $row[0], $row[1]];
}
mysql_free_result[$result];
?>