Forum Moderators: open

Message Too Old, No Replies

simple SELECT query acting strange

adding ORDER BY limits results shown

         

stef25

2:35 pm on May 28, 2007 (gmt 0)

10+ Year Member



i have the following, simple query with some basic php to extract and display the results. there are 5 rows in the articles table with primary keys from 77 - 81. the query below does not show $title for article with id = 80


$queryGetArticles = "SELECT * FROM articles";
$resultGetArticles = mysql_query($queryGetArticles) or die ("couldnt get the data");
$row = mysql_fetch_array($resultGetArticles);
while ($row = mysql_fetch_array($resultGetArticles,MYSQL_ASSOC)) {
extract ($row);
echo "$title <br />";
}

if i then change the query to the line below, adding a simple ORDER BY clause, article 77 shows, but article 80 does not!

$queryGetArticles = "SELECT * FROM articles ORDER BY articleID";

i dont think this is a problem with my queries but rather with a mistake in the structure of my db ... thats all i can think of. is this possible?

stef25

7:58 pm on May 28, 2007 (gmt 0)

10+ Year Member



nevermind, im using mysql_fetch_array twice!

eelixduppy

2:26 am on May 29, 2007 (gmt 0)



That will do it; by calling it twice, the internal pointer was already advanced by once before you starting echoing info to the browser. Glad you figured it out :)