SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
    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.

    PHP Code:
    <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,

  2. #2
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    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.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI.
    Ok I will change to standard tags. Here is the HTML. I just cant understand why the first record dissapears.

    HTML Code:
    <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>

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    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.

  5. #5
    Non-Member Max Height's Avatar
    Join Date
    Dec 2011
    Posts
    303
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by guido2004 View Post
    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

    @op

    get rid of the blue line

    Code:
    $rsLocations = mysql_query($query_rsLocations, $db) or die(mysql_error()); 
    $row_rsLocations = mysql_fetch_assoc($rsLocations); 
    $totalRows_rsLocations = mysql_num_rows($rsLocations);
    mysql_fetch_assoc() retrieves a row from the result set and then moves the internal pointer to the next row.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That Worked! I dont know what I would do without you guys!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •