username01 Posted February 9, 2011 Share Posted February 9, 2011 while($row = mysql_fetch_row($query)) { echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } Currently I have this code. I would like to make it print certain text, let's say... 'car', if the value of table's column 'automobiles' is equal to 0. Otherwise - print the real value. I've tried if statement and $one = $two... But that apparently didn't worked. Thanks. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2011 Share Posted February 9, 2011 But that apparently didn't worked. It didn't work because = is assignment. == is comparison. Quote Link to comment Share on other sites More sharing options...
username01 Posted February 9, 2011 Author Share Posted February 9, 2011 while($row = mysql_fetch_row($query)) { if $row == '0' {$row = $text_specified} echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } My equation syntax is correct, but code is wrong. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2011 Share Posted February 9, 2011 if $row == '0' {$row = $text_specified} Row won't equal 0. one of the values in row could be. row[0] might = 0, or row[1]. But row will never because of the while. You need to check on EACH column/key Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted February 9, 2011 Share Posted February 9, 2011 if(mysql_num_rows($query)) { while($row = mysql_fetch_row($query)) { echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } } else { echo 'No rows returned'; } Use the above code, if mysql_num_rows() returns 1 or more rows it will equate to true, else it will equate to false. Regards, PaulRyan. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2011 Share Posted February 9, 2011 if(mysql_num_rows($query)) { while($row = mysql_fetch_row($query)) { echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } } else { echo 'No rows returned'; } Use the above code, if mysql_num_rows() returns 1 or more rows it will equate to true, else it will equate to false. Regards, PaulRyan. That doesn't sound like what the OP wants to DO though. "if the value of table's column 'automobiles' is equal to 0. Otherwise - print the real value." That refers to one column in the row. Not the whole row. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted February 9, 2011 Share Posted February 9, 2011 Well spotted Jesirose, I totally mis-read the post, my bad! Regards, PaulRyan. Quote Link to comment Share on other sites More sharing options...
username01 Posted February 9, 2011 Author Share Posted February 9, 2011 Thanks, but it didn't worked still: while($row = mysql_fetch_row($query)) { if $row[3] == '0' {$row[3] = $value_text} echo "<tr>"; echo '<td>' . $row[0] . '</td>'; echo '<td>' . $row[1] . '</td>'; echo '<td>' . $row[2] . '</td>'; echo '<td>' . $row[3] . '</td>'; echo '<td>' . $row[4] . '</td>'; echo "</tr>\n"; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 9, 2011 Share Posted February 9, 2011 Before all your echo's, add print_r($row); and show us what it says Quote Link to comment Share on other sites More sharing options...
username01 Posted February 10, 2011 Author Share Posted February 10, 2011 It doesn't load the page at all. It's a blank page either way, so I can't tell you that. :/ Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2011 Share Posted February 10, 2011 Then you have an error and you don't have error reporting turned on or set high enough. Quote Link to comment Share on other sites More sharing options...
username01 Posted February 10, 2011 Author Share Posted February 10, 2011 How can I turn that... error reporting on? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2011 Share Posted February 10, 2011 | | | V Quote Link to comment Share on other sites More sharing options...
username01 Posted February 10, 2011 Author Share Posted February 10, 2011 Where should I put that error_reporting() and E_ALL? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2011 Share Posted February 10, 2011 Where would make sense? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.