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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/ 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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171796 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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171854 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 Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171856 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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171860 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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171866 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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171896 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"; } Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1171955 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 Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172050 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. :/ Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172098 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. Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172100 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? Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172102 Share on other sites More sharing options...
Jessica Posted February 10, 2011 Share Posted February 10, 2011 | | | V Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172109 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? Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172126 Share on other sites More sharing options...
Jessica Posted February 10, 2011 Share Posted February 10, 2011 Where would make sense? Link to comment https://forums.phpfreaks.com/topic/227161-print-specified-text-if-the-sql-tables-columns-value-is-0/#findComment-1172131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.