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