While Loop Not Returning 1st Record

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

While Loop Not Returning 1st Record

Post by PastorHank »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

$query = "SELECT * FROM thunde9_thunderhill.journals ORDER BY 2 DESC"; 
// ***The Query should return 4 records - records are verified via MYSql Query Browser all four show up****

   $result = mysql_query($query)
		or die ("Couldn't Execute Query.");
 $row = mysql_fetch_array($result,MYSQL_ASSOC); 
  $animaltype="Ranch Observations";
 

// ****Title displays correctly

 echo "<h1 align='center'> <font color='#EEE4BC'>$animaltype</h1>";

 echo "<div align='center'>";
 echo "<table border='1' bgcolor='#EEE4BC'>";

 // ***1st Record or Title Shows Correctly 
 echo "<tr> <th>Date Created</th>
 			<th>Created By</th>
 			<th>Observation</th>
 			</tr>";

// ****for some reason this only displays records 2,3,4 omitting record 1
while ($row = mysql_fetch_array($result))
			{
  extract($row);
  echo "<tr>
  		<td align='center'>$datecreated</td>
  		<td align='center'>$createdby</td>
  		<td width='300' align='center'>$journalentry</td>
 		</tr>";
 }
What have I messed up?
thanks


Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

the reason is that you've fetched the first record before even entering the loop. Remove the first occurence of mysql_fetch_array (just after the mysql_query call)
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

Thank you. I'll read those rules also.

Thanks again
Post Reply