query results incomplete

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
ggoose
Forum Newbie
Posts: 4
Joined: Tue Mar 09, 2010 1:52 pm

query results incomplete

Post by ggoose »

Hello,
I have a web page with a link that uses Php/MySQL to return posted comments between specific dates, but the results returned always lack the most recent post if ORDER BY DESC or the very first post if ORDER BY ASC. As my programming skills are wanting, I thought perhaps someone here might point out my error(s). Here is the code...

Code: Select all

<?php
	   $getdata = mysql_query("SELECT * FROM djm_req WHERE time_stamp BETWEEN '2010-05-01 00:00:00' AND '2010-05-31 23:59:59' ORDER BY entryID DESC")  OR DIE;
	   IF (mysql_fetch_array($getdata) == 0)  { //If there are no requests posted with the given time, echo:
	     echo "<p class='center' style='text-align: center;'>No Requests Posted</p>";
	   }  ELSE  { 
	         WHILE ($getdata2 = mysql_fetch_array($getdata))  {
		 $getdata2['salut'] = strip_tags($getdata2['salut']);  //Removes all HTML and Php tags from salut...
		 $getdata2['request'] = strip_tags($getdata2['request']);  //Removes all HTML and Php tags from request...
		 $salut = $getdata2['salut'];
		 $request = $getdata2['request'];
		 $timestamp = strtotime($getdata2['time_stamp']);
		 $localtime = ($timestamp - 10800);  //This is -3 hrs to make up timezone difference from west coast local time to east coast server time.
		 $date = date("l, F dS, Y @ g:i a", $localtime);
					
		//Print out the resuslts for each posting
				echo "<div style='width: 95%; border: 1px solid gray; padding: 10px 10px 0 10px; margin: 5px 0; text-align: left;'>";
				echo "<h3>" .$salut. ",</h3>";
				echo "<p class='center'>" .nl2br($getdata2['request']). "</p>";
				echo "<p style='font-size: 9pt; font-style: italic;'>Posted: " .$date. "</p>";
				echo "</div>";
	  } 
	}
?>
I am using WAMP Server 2 (Php 5.3, MySQL 5.1.36 on Windows 7)
Thanks for any help...
ggoose
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: query results incomplete

Post by mikosiko »

missing always the first record.... there is a big hint there :)

read here http://php.net/manual/en/function.mysql-fetch-array.php and pay special attention to what the "Description" say.

Miko
ggoose
Forum Newbie
Posts: 4
Joined: Tue Mar 09, 2010 1:52 pm

Re: query results incomplete

Post by ggoose »

Thanks MIko,
With your clue I was able to get the query results to properly dislplay :D
ggoose
Post Reply