Jump to content

Print specified text, if the SQL table's column's value is 0.


username01

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.