SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Missing first record in PHP / MySQL page

    Hi,

    I'm not sure if the following is a MySQL or PHP issue but would appreciate all advice.

    I have a page where a list of names are to be displayed. I present the user the option of choosing the sort order using links of the letters A-Z but also the option to show all names on the same page.

    I thought it was working fine but have just realised that in each case the very first record is missing from any choice. So, for example if the user clicks "A" the first name displayed should be Adami, Valerio followed by Adela, R.D. etc. In fact the first name is skipped and all names from the second onwards print fine. This happens with all choices A-Z and with the show all option (in this case Adami is the only record skipped as he is the first).

    The page can be viewed here (with code extracts included below):

    http://www.circulodelarte.com/produc...lang=es&sort=a

    Can anyone can shed any light as to where this error is being caused and how it might be fixed?

    Many thanks,

    Gary Crighton

    CODE EXTRACTS:

    My sort links takes the following form:

    <a href="<?PHP $PHP_SELF ?>?lang=<?PHP echo $lang ?>&sort=a">A</a>


    My select statement:

    if ($sort == "all") {
    $result = mysql_query ("SELECT * FROM biografias WHERE Tipo = 1 ORDER BY nombre");
    } else {
    $result = mysql_query ("SELECT * FROM biografias WHERE Tipo = 1 AND LOWER(SUBSTRING(nombre,1,1)) = '$sort' ORDER BY nombre");
    }


    Printout statements as follows:

    <?
    if ($row = mysql_fetch_array($result) == "") {
    ?>

    Etc...

    <?
    } else {
    while ($row = mysql_fetch_array($result)) {
    ?>

    <tr><td class='list'>
    <a href='/production/artistas/artistas_detalle.php?lang=<?PHP echo $lang ?>&ID=<?PHP echo $row["ID"]?>'><?PHP echo $row["Nombre"]?></a>
    </td></tr>

    ?>

    Etc...

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Missing first record in PHP / MySQL page

    i think the problem lies here:
    PHP Code:
    <?
    if ($row mysql_fetch_array($result) == "") {
    ?>
    this causes a row to be fetched since you call mysql_fetch_array()... that row is then skipped over in the while loop since it's already been retrieved...

    to test whether there're records, use:
    PHP Code:
    if(!$result)
    {
      echo 
    "No results!";


  3. #3
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Re: Missing first record in PHP / MySQL page

    Originally posted by redemption

    to test whether there're records, use:
    PHP Code:
    if(!$result)
    {
      echo 
    "No results!";

    Is that right? I always thought that you needed something like mysql_num_rows==0 to see if it was empty... and that if(!$result) that meant "Couldn't DO $result!" sort of thing...
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  4. #4
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah-hem you're right... my mistake


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
  •