Link to home
Start Free TrialLog in
Avatar of ChrisAndrews
ChrisAndrews

asked on

Error in while statement


Hi,

I seem to have an error in the while statement below, my 'print' prints that line three times instead of once, the proceeds to the next, then again prints it three times before moving on to the next, and so on...

I don't have much exp with this, just adapted it from another script, can you tell me what is wrong?

Thanks,     Chris

--------------------------

//get data

$query = "SELECT * FROM user where Number > 0 order by Number";

$result = MYSQL_QUERY($query);

$number = MYSQL_NUMROWS($result);

/*display results*/

$i = 0;

IF ($number == 0) :
PRINT "ERROR, database seems to be out to lunch.  Drop a note to Chris and he will look into it.";
ELSEIF ($number > 0) :
WHILE ($i < $number):
$ordernumber = mysql_result($result,$i,"Number");
$account = mysql_result($result,$i,"Account");
$order_date = mysql_result($result,$i,"Order_Date");
$name = mysql_result($result,$i,"Name");
$status = mysql_result($result,$i,"Status");
$month1 = mysql_result($result,$i,"$date1");
$month2 = mysql_result($result,$i,"$date2");
$month3 = mysql_result($result,$i,"$date3");
$month4 = mysql_result($result,$i,"$date4");

PRINT "<tr><td>$ordernumber</td><td>$account</td><td>$order_date</td><td>$name</td><td>$status</td><td>$month4</td><td>$month3</td><td>$month2</td><td>$month1</td></tr>";


$i++;  
ENDWHILE;
ENDIF;
ASKER CERTIFIED SOLUTION
Avatar of lozloz
lozloz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChrisAndrews
ChrisAndrews

ASKER


Hi loz,

Thank you, I am still getting three of each 'print' line, hmmm, what could be causing this?  

oh, just checked the database, phpmyadmin reports 134 rows when there should 45.

 When I browse the rows there is only 45 rows.  I don't know what is happening there, I may need to rebuild the table?

Any thoughts?   I will send these points to you because the suggested script is good, if you have any thoughts about
this let me know :)

Chris
best thing to do would be to dump the table and to look through it to see what's going wrong, paste it here if you want help identifying the problem

loz

ah loz, your so smart :)  dumped the table, found multiple entries, cleaned it out and all is well.... course, now I will run my scripts again and try to figure out what goofed it up in the first place.  May have just been me testing over and over did something in.

Thank you,

Chris