Disappearing Record

Hello All!
I have a small issue that Im sure its due to something minor that I am overlooking but Ive been working on this for hours and cant seem to catch the issue.

Basically I have a query that is looking up locations of a certain type of course.
It looks at a table that lists all locations that are active and returns a list of states where we have courses. The INNER JOIN is transforming the State abbreviation to the proper state name using a table called STATES.
Then its returned to a 4 column table. However for some reason the first location is missing.

On the php page it leaves out the first state (Arizona), but running the same query on PHPMyadmin returns the appropriate states. Here is the code":

Query


mysql_select_db($database_db, $db);
$query_rsLocations = "SELECT DISTINCT
  locations.locationstate,
  locations.locationstatus,
  USStates.statename
 FROM
 locations
 INNER JOIN USStates ON (locations.locationstate=USStates.stateabr)
WHERE
  locations.locationstatus = 'active'
ORDER BY
  locations.locationstate";
$rsLocations = mysql_query($query_rsLocations, $db) or die(mysql_error());
$row_rsLocations = mysql_fetch_assoc($rsLocations);
$totalRows_rsLocations = mysql_num_rows($rsLocations);

Code for table. THis is where the first record goes missing.


<table class="statelisttable" width="500px" align="center">
          <?php $clm = 1;
              while($row_rsLocations = mysql_fetch_assoc($rsLocations)){
              if($clm == 1){ echo "<tr>"; } ?>
              <td><a href="CPR_Classes_In_<?php echo $row_rsLocations['locationstate']; ?>.html">
			 <?php
			 $filename = "images/flags/" . $row_rsLocations['locationstate'] . ".jpg";
			 if (file_exists($filename)) {
			 echo "<img src=images/flags/" . $row_rsLocations['locationstate'] . ".jpg>";
			 } else {
			echo "<img src=images/flags/US.jpg>";
			}?><br>
			<?php echo $row_rsLocations['statename']; ?></a></td>
          <? if($clm == 4){
              echo "</tr>";
              $clm = 1;
             }else{
             $clm++;
             }
              }
             if($clm == 1) { echo "<td>&nbsp;</td></tr>"; }
          ?>
             </table></div>

Really appreciate your help on this before i go nuts!!!

thanks again,

You’re jumping in and out of php tags (and you’re mixing standard php tags with short tags) which is making it confusing.

Why not simply have all the php code creating the <tr>s and <td>s in just 1 set of php tags inside your <table>? In any case it would be easier to see what is going on if you also post the actual html the php code creates for the table.

HI.
Ok I will change to standard tags. Here is the HTML. I just cant understand why the first record dissapears.

<h5>States</h5>
 <table class="statelisttable" width="500px" align="center">
          <tr>              <td><a href="Classes_In_CA.html">
			 <img src=images/flags/CA.jpg><br>
			California</a></td>
                        <td><a href="Classes_In_CO.html">
			 <img src=images/flags/US.jpg><br>
			Colorado</a></td>
                        <td><a href="Classes_In_HI.html">
			 <img src=images/flags/HI.jpg><br>
			Hawaii</a></td>
                        <td><a href="Classes_In_NV.html">
			 <img src=images/flags/US.jpg><br>
			Nevada</a></td>
          </tr><tr>              <td><a href="Classes_In_OK.html">
			 <img src=images/flags/OK.jpg><br>
			Oklahoma</a></td>
                        <td><a href="Classes_In_PR.html">
			 <img src=images/flags/PR.jpg><br>
			Puerto Rico</a></td>
                        <td><a href="Classes_In_TX.html">
			 <img src=images/flags/TX.jpg><br>
			Texas</a></td>
                        <td><a href="Classes_In_UT.html">
			 <img src=images/flags/UT.jpg><br>
			Utah</a></td>
          </tr><td>&nbsp;</td></tr>             </table></div>

You do a first fetch right after you run the query, and before you reach the while loop.
That’s why the first row is never shown.

ah yes, good catch :slight_smile:

@op

get rid of the blue line

[COLOR=#000000]$rsLocations = mysql_query($query_rsLocations, $db) or die(mysql_error()); 
[/COLOR][COLOR=#0000ff]$row_rsLocations = mysql_fetch_assoc($rsLocations); [/COLOR][COLOR=#000000]
$totalRows_rsLocations = mysql_num_rows($rsLocations);[/COLOR]

mysql_fetch_assoc() retrieves a row from the result set and then moves the internal pointer to the next row.

That Worked! I dont know what I would do without you guys!