SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    All records not getting displayed in MySQL Database

    Hi,

    I am trying arrange records, which contain the first letters of a group of companies, from my database in columns, and this is my SQL query:

    Code:
    mysql_select_db($database_directory, $directory);
    $query_mda = "SELECT DISTINCT mdal FROM mda ORDER BY mdal ASC";
    $mda = mysql_query($query_mda, $directory) or die(mysql_error());
    $row_mda = mysql_fetch_assoc($mda);
    $totalRows_mda = mysql_num_rows($mda);
    This is my PHP code for arranging the records:

    Code:
    <?php 
    $cols = 10;
    $count = 0;
    echo("<table align=\"center\"><tr>");
    while($row_mda = mysql_fetch_array($mda)) {
        if($count % $cols == 0)
            echo("</tr><tr>");
        echo ("<td align=\"center\">"."&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;"."<a href=\"list.php?mdal=".$row_mda['mdal']."\" class=\"listTextA\">".$row_mda['mdal']."</a>"."&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;"."&nbsp;");	
    echo("</td>");
    $count++;
    
    }
    echo("</tr></table>");
    ?>
    The problem I am encountering is that it displays all the records except the first record. Please what am I doing wrong?

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this ...
    PHP Code:
    $row_mda mysql_fetch_assoc($mda); 
    is getting the first record, thereby causing the pointer to move to the 2nd record.

    Either delete that line or reset the pointer prior to your WHILE loop
    http://php.net/manual/en/function.mysql-data-seek.php

  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by litebearer View Post
    this ...
    PHP Code:
    $row_mda mysql_fetch_assoc($mda); 
    is getting the first record, thereby causing the pointer to move to the 2nd record.

    Either delete that line or reset the pointer prior to your WHILE loop
    http://php.net/manual/en/function.mysql-data-seek.php
    Deleting $row_mda = mysql_fetch_assoc($mda); worked fine...thanks.


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
  •