Jump to content

PHP+Results


01hanstu

Recommended Posts

To get the number of results a query returned use mysql_num_rows, example

 

$total_rows = mysql_num_rows(QUERY RESULT VARIABLE HERE);

 

To set the background color based on what $total_rows is set to you'd use an if/elseif/else statement

 

// set $bgcolor based $total_rows
// if $total_rows is equal to 3, bcolor is set to red
if($total_rows == 3)
    $bgcolor = 'red';
// if $total_rows is greater than 3, bcolor is set to blue
elseif($total_rows > 3)
    $bgcolor = 'blue';
// $total_rows is not equal to 3 or is not greater than 3, bgcolor is set to white
else
    $bgcolor = 'white';

 

To change the background of the table you can either use the bgcolor html attribute, example

<table bgcolor="<?php echo $bgcolor; ?>">
<tr><td>some cells</td></tr>
</table>

Or using (inline ) CSS, example

<table style="background-color: <?php echo $bgcolor; ?>">
<tr><td>some cells</td></tr>
</table>

Link to comment
https://forums.phpfreaks.com/topic/190445-phpresults/#findComment-1004606
Share on other sites

Hi,

Thanks wildteen88. Unfortunately what I need is for it to read the data from the table, print it and if the data is more that 3 characters then bg color of td = red, if it is 3 then print blue.

 

Its a booking system and when staff book, it uses there name (Which is more that 3 chars), but when we fill in the permanent bookings then we use the staff code (Three letters).

 

Thanks

Stu

Link to comment
https://forums.phpfreaks.com/topic/190445-phpresults/#findComment-1004703
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.