Forum Moderators: coopster
The script snippet below displays all records of a given date, but it always leaves off the first record. And if there is only one record for that date, it appears blank. What am I doing wrong, that it skips the first record?
Thank you :)
Code:
$Day = $_GET['Day'];
$Year = $_GET['Year'];
$Month = $_GET['Month'];
$cal_string = date("Y-m-d", strtotime("$Month $Day $Year"));
$sqlquery = "SELECT id, diwtitle, date_string FROM diw_alpha WHERE date_string = '$cal_string'";
$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");
$row = mysql_fetch_row($queryresult);
$date_string = $row[0];
$diwtitle = $row[1];
$id = $row[2];
$tdcount = 1;
$numtd = 1; // number of cells per row
while($row = mysql_fetch_array($queryresult)) {
if ($tdcount == 1) echo "<tr>";
echo '<td>'.$row['date_string'].'</td><td><a href="damndiw4.php?id='.$row['id'].'"> '.$row['diwtitle'],'</a></td><td>'.$row['id'].'</td>';
if ($tdcount == $numtd) {
echo "</tr>";
$tdcount = 1;
} else {
$tdcount++;
}
}
// close up table
if ($tdcount!= 1) {
while ($tdcount <= $numtd) {
echo "<td> </td>";
$tdcount++;
I follow you in your explanation.. I am pretty green to PHP, I am not sure how to implement a fix for this, whether it's a slight alteration to existing code, or if what I want to accomplish needs a complete re-write. Can you point me in the right direction?
EDIT: I notice that when I echo the variable $date_string, it returns the value of the id of the first record which is not displayed.. I am trying to debug this, and I am sure this is what's causing the initial problerm
do{
}while($row = mysql_fetch_array($queryresult))
so you always get the first record before you move the pointer.
That's how I do it.
[us2.php.net...]
Good Luck
$row = mysql_fetch_row($queryresult);
so when it gets here
while($row = mysql_fetch_array($queryresult)) {
it is always on the second row
maybe try mysql_data_seek [php.net] before your fetch array to reset the pointer