[CS-FSLUG] Why one but not the other (SQL query)

David McGlone d.mcglone at att.net
Sat Dec 27 12:13:28 CST 2008


First, forgive me if I am being annoying, I don't know where else to turn to 
for help.

Here are 2 queries I've been studying, and I can't figure out why one query 
only outputs the first 5 rows, when there are actually 6 rows in the database. 
But when I use the second query, it outputs all 7 rows. The behaviour of each 
query leave me confused wondering why the first query will not output all 7 
rows. 

first query:
$query = "SELECT * FROM subheaderText";
$result= mysql_query($query);
$num = mysql_fetch_array($result);
$num=0;
while ($num < $result){
echo "$subheaderTextID<br>"; 
$num++;
echo $num;
}
this query echo's back: 12345.

In the above code, I believe that $result should contain all 6 rows, so even 
when starting with $num=0 the while loop should loop through and display all 7 
rows because it is incremented with $num++ and should not stop until it goes 
through all the rows. am I correct?

second query:
$query = "SELECT * FROM subheaderText";
$result= mysql_query($query);
while ($num=mysql_fetch_array($result)){
echo "$num[subheaderTextID]";
}
this query echo's back: 1234567

-- 
David M.
http://www.dmcentral.net




More information about the Christiansource mailing list