By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

while($row = ) fetch row from table show not complete result..

P: 5
when we do mysql_query with while and mysql_num_rows() together then while do no show the first row from table in database..

example :
<?
$conn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable toconnect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName"); $sqlquery = "SELECT * FROM $table WHERE opinion = 'is great'";
$result = mysql_query($sqlquery,$conn);
$number = mysql_num_rows($result); //to get the total rows

echo "Total row is " . $number ;

while($rows = mysql_fetch_assoc($result)) //show all the values in all rows in table

{
echo $uid = $row['id'];
echo $name = $row[''name];
}
//while show not the first value in the row , to show the value in first and all other //rows we have to run the another $sql_query and that is not good idea ...
exit;
?>

please tell me how to resolve it...thanks..
Sep 15 '06 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Your result set is in $rowS, while you get your values from $row (without the S).
So this statement
[PHP]while($rows = mysql_fetch_assoc($result)) {
[/PHP]
must be changed to
[PHP]while($row = mysql_fetch_assoc($result)) {
[/PHP]

Ronald :cool:
Sep 15 '06 #2

P: 5
Hello,

that was just in hurry while posting, that S, nut when i code is all right . coding is not problem, if any code wrong then , script does not run.

you try with same sql query for num rows and while(),

try it i am running all my db system, thing is if it work proper then i had not to run two different sql query...

thanks
Sep 16 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.