Selecting All From Database - Isnt Selecting All :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
micky007
Forum Newbie
Posts: 8
Joined: Mon Mar 14, 2011 1:43 pm

Selecting All From Database - Isnt Selecting All :(

Post by micky007 »

Hi,

I have 7 records in my database, im running PHP code to connect to my database and display ALL from the database/table but its only displaying 4 out of the 7 records. How come?

Code: Select all

<?php
$username="REMOVED";
$password="REMOVED";
$database="REMOVED";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

$query="SELECT * FROM leads";
$result=mysql_query($query);
$num=mysql_numrows($result) or die(mysql_error());
?>
<table width="100%" border="1">
 <tr>
    <th><em><strong>ID</strong></em></th>
    <th><em><strong>Name</strong></em></th>
    <th><em><strong>Email</strong></em></th>
    <th><em><strong>Telephone</strong></em></th>
    <th><em><strong>Venue</strong></em></th>
    <th><em><strong>When</strong></em></th>
    <th><em><strong>Date</strong></em></th>
    <th><em><strong>Time</strong></em></th>
    <th><em><strong>IP</strong></em></th>
  </tr>
  
<?php
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"ID");
$first=mysql_result($result,$i,"Name");
$email=mysql_result($result,$i,"Email");
$telephone=mysql_result($result,$i,"Telephone");
$venue=mysql_result($result,$i,"Venue");
$call=mysql_result($result,$i,"When");
$dateentered=mysql_result($result,$i,"Date");
$timeentered=mysql_result($result,$i,"Time");
$ip=mysql_result($result,$i,"IP");
?>
<tr>
<td><? echo $id; ?></td>
<td><? echo $first; ?></td>
<td><? echo $email; ?></td>
<td><? echo $telephone; ?></td>
<td><? echo $venue; ?></td>
<td><? echo $call; ?></td>
<td><? echo $dateentered; ?></td>
<td><? echo $timeentered; ?></td>
<td><? echo $ip; ?></td>
</tr>
<?
$i++;

$i++;
}
mysql_close();
?>

</table>
Any help would be great.

Thanks
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: Selecting All From Database - Isnt Selecting All :(

Post by litebearer »

you are incrementing $i twice - effectively getting every other record
micky007
Forum Newbie
Posts: 8
Joined: Mon Mar 14, 2011 1:43 pm

Re: Selecting All From Database - Isnt Selecting All :(

Post by micky007 »

Thank you....!
Post Reply