SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    row 0 not showing in results

    I have 3 matching records for my query (they show normally in phpMyAdmin) but with my PHP code only rows 1 and 2 show.

    Why is row 0 not showing? What is wrong with my code below?

    <?
    include("XXXXXXXX");

    $connection = mysql_connect($host,$user,$password)
    or die ( mysql_error() );
    $db = mysql_select_db($database,$connection)
    or die ( mysql_error() );
    $query = " SELECT * FROM mag_toc
    WHERE category='30'
    AND date_archive='$q_date'";
    $result = mysql_query($query)
    or die ( mysql_error() );

    $row = mysql_fetch_array($result);
    if($row)
    {
    extract($row);
    echo "<p class=\"header-burgundy\">Weekly News from Investment & Technology</p>";
    while ($row = mysql_fetch_array($result))
    {
    extract($row);
    echo"<p>
    <b>".$title."</b><br />".
    $description."<br /><a href=\"http://www.investmenttechnology.com.au/body/article_view.php?id=".$id."\">read more...</a></p>";
    }
    }

    ?>

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you call:
    $row = mysql_fetch_array($result);
    you are fetching the first row and advancing to the next row. You do not display any data from it and then you call:
    while ($row = mysql_fetch_array($result))
    to get the remaining rows. This is why you are losing the first row of data.

    Hope this helps.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK so what would be the correct syntax to get display all the rows?

  4. #4
    SitePoint Zealot swiftone's Avatar
    Join Date
    Mar 2005
    Location
    Sunny Florida
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am posting this quickly, and may be wrong, but will this work?
    PHP Code:
    include("XXXXXXXX");

    $connection mysql_connect($host,$user,$password) or die ( mysql_error() );
    $db mysql_select_db($database,$connection) or die ( mysql_error() );
    $query " SELECT * FROM mag_toc WHERE category='30' AND date_archive='$q_date'";
    $result mysql_query($query) or die ( mysql_error() );
    $row_result mysql_fetch_assoc($result);

    if(
    $row_result) {
        do {
            echo
    "<p><b>".$title."</b><br />".$description."<br /><a href=\"http://www.investmenttechnology.com.au/body/article_view.php?id=".$id."\">read more...</a></p>";
        } while (
    $row_result mysql_fetch_assoc($result));

    Happy Coding,
    Swiftone

    Unique Web Sites

  5. #5
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
           $result mysql_query($query);
      if (
    mysql_num_rows($result) > 0) {
        
    // at least one row has been returned
        
    while ($row mysql_fetch_array($result)) {
          echo 
    $row['title'] . '<br />'// etc
        
    }
     }
     else {
     
    // no rows were returned
     


  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2004
    Location
    sydney
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks it worked just fine!


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
  •