I have this code
$sql5 = "SELECT * FROM iptable
WHERE user_id = '$userid_c' AND ip = '$ip' LIMIT 0, 30 ";
$query5=mysql_query($sql5);
$row_ip_a = mysql_num_rows($query5);
When I use this from phpmyadmin it returns fine results but when I use it from php it always returns one row.
开发者_开发知识库What could be the reason?
mysql_num_rows — Get number of rows in result
<?php
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";?>
U need this: mysql_fetch_array — Fetch a result row as an associative array, a numeric array, or both
Your Code Just Yields with number of rows affected, where as u need the data from select query
hence You can use mysql_fetch_array as:
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
Without seeing your data set, it's hard to see whether you're getting the same results.
Assuming that when you put it in PHPMyAdmin, you fill out $userid_c
and $ip
with manual values? Try plugging in these manual values instead of the variables above, and see whether that works (if it does, then there's a problem with your variables).
精彩评论