Weird results from database

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
guymclaren
Forum Newbie
Posts: 11
Joined: Tue Feb 17, 2009 10:53 pm

Weird results from database

Post by guymclaren »

Code: Select all

 
10 10   10  10  10
        1   1
The above is the result I get from this code

Code: Select all

$sqlq="SELECT * FROM Members";
$objRS = mysql_query($sqlq);
$num = mysql_numrows($objRS);
?>
 
<div id="content">
<div id="contentleft">
<h2>Lede Betaal geskiedenis</h2>
<table>
 
<?
 
$i=0;
while ($i < $num) {
$email = mysql_result($objRS,"email");
$name = mysql_result($objRS,"Name");
$sname = mysql_result($objRS,"Surname");
$neename = mysql_result($objRS,"Nee");
$city = mysql_result($objRS,"City");
$reference = mysql_result($objRS,"id");
 
$sqlm = "SELECT * FROM fees WHERE member = '".$reference."'";
$objRSi = mysql_query($sqlm);
$numi = mysql_numrows($objRSi);
 
 echo "<tr><td>".$name." ".$sname." </td><td>".$neename." </td><td>".$email." </td><td>".$city."</td></tr>"; 
        
        $j=0;
        while ($j < $numi) {
 
            $amount = mysql_result($objRSi, "amount");
            $date = mysql_result($objRSi, "Date");
            echo "<tr><td></td><td></td><td align=right>".$date." </td><td align=right> ".$amount."</td></tr>"; 
            $j++;
            }
 
$i++;
}
 
?>
</table></div>
I was expecting a name and surname, then a blank field, an email address and a city on line 1
on line two I was expecting a date and a number. What have I done wrong? Please help.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Weird results from database

Post by VladSun »

Use mysql_fetch_assoc() instead of mysql_result()
Take a look at the examples there.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply