Does not show all the records

Discussion in 'PHP' started by peterbaker11, Jul 27, 2010.

  1. #1
    I have a real funny one I call a batch of records from the DB and I don't know why it always misses the first record?? any ideas.... (code below)

    $x = 0;
    $sql = "select * from interest where Number = \"$cid\" ";
    $data = mysql_query($sql)or die("Couldn't execute query");
    $result = mysql_fetch_array( $data );
    while($result = mysql_fetch_array( $data ))
    {
    if($x % 2 == 0) {
    $bg = "#ffffcf";
    }
    else {
    $bg = "#ffffff";
    }
    echo "<tr bgcolor=$bg class=row ><td width='120'>";
    echo $result['Name'];
    echo "</td><td >";
    echo $result['Locality'];
    echo "</td><td width='100'>";
    echo $result['County'];
    echo "</td><td width='80'>";
    echo $result['Period'];
    echo "</td>";
    echo "</tr>";
    $x ++;
    }
     
    peterbaker11, Jul 27, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    What exactly do you mean, its not catching 'name', maybe its not called 'name' or name is in another table ?
     
    MyVodaFone, Jul 27, 2010 IP
  3. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #3
    Does the table begin at 0?
     
    mcfox, Jul 27, 2010 IP
  4. Martin K

    Martin K Active Member

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    chnage
    to
     
    Martin K, Jul 29, 2010 IP
  5. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #5
    You're not gunna want to put php tags inside other php tags, but you definately need quotes around the tag information:

    
    echo "<tr classs='row' bgcolor='{$bg}'><td width='120'>";
    
    PHP:
    As far as missing the first row goes, the only reason it wouldn't display is if the it doesn't match the Number=$cid. Also, it shouldn't make a difference because your backslashes do the same thing, but try this as your sql statement:

    $sql = "SELECT * FROM interest WHERE Number='{$cid}'";
    PHP:
     
    Thorlax402, Jul 30, 2010 IP