Re: If statement duplicating mysql records?
| From: | Jim Lucas | Date: | Wed, 20 Jun 2007 14:38:17 +0000 |
| Subject: | Re: If statement duplicating mysql records? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257492@lists.php.net to get a copy of this message | ||
Jason Pruim wrote:
On Jun 19, 2007, at 4:20 PM, Jim Lucas wrote:I would look at your result set and see if you had multiple lines returned. One person mentioned that you might be using a JOIN in you SQL call. This could lead to multiple lines. Start investigating your SQL statement I would suggest. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." UnknownJason Pruim wrote:And that just goes to show how much I have yet to learn! Once I typed that out I went from like, 86 lines of code down to 55... And it works as well! Just for my own knowledge, Do you know why the else was being applied after the condition was met? Thanks Jim! nope, couldn't guess why.Okay, so I have a question... Probably pretty easy, but why would my if statement show more records then what are in the database? if($row[5] =='Level4'){ // White HighlightWhy not do it this way instead. while( $row = mysql_fetch_array($results) ) {echo "<TR><TD bgcolor=".$Level4.">$row[0] </td>"; echo "<td bgcolor=".$Level4.">$row[1] </td>"; echo "<td bgcolor=".$Level4."><A href ='$row[2]'>Instructions</A></td>"; echo "<TD bgcolor=".$Level4."><A href='update.php?taskid=$row[0]'>Click here!</A>"; }// End of Level 4 else {// Green Highlight echo "<TR><TD bgcolor=".$unclassified.">$row[0] </td>"; echo "<td bgcolor=".$unclassified.">$row[1] </td>"; echo "<td bgcolor=".$unclassified."><A href ='$row[2]'>Instructions</A></td>"; echo "<TD bgcolor=".$unclassified."><A href='update.php?taskid=$row[0]'>Click here!</A>"; }// End of Unclassified$rowColor = $unclassified;// White Highlight if($row[5] =='Level4'){ $rowColor = $Level4; }echo "<TR><TD bgcolor=".$rowColor.">$row[0] </td>"; echo "<td bgcolor=".$rowColor.">$row[1] </td>"; echo "<td bgcolor=".$rowColor."><A href='$row[2]'>Instructions</A></td>"; echo "<TD bgcolor=".$rowColor."><A href='update.php?taskid=$row[0]'>Click here!</A>";}