Page 1 of 1

Numbers to yes/no

Posted: Mon Feb 27, 2012 11:52 am
by vampiro
Right I have the following PHP code that pulls from our database and displays customer contact info along side their name. What i am trying to do is pull in the cover table and put it as yes/no for if they are under our cover or not. the database holds their level of cover as 0= no cover to 5= highest cover etc, i am wanting to put these in a table which as you can see works but at the moment just displays the numbers.

I have tried verious code snipetts from the internet but as i know very little about PHP i have suprised meself getting this far....


This is the current code i have:

Code: Select all

<?php include ("header.php"); ?>
<a href="menu.php">Back</a>
<?php

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM customers WHERE Status>0 && Level>=" . $_SESSION['eng_level'] . " ORDER BY Name ASC")
or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Phone Number</th> <th>on Cover</tr> </tr> ";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['Name'];
	echo "</td><td>";
	echo $row['TelephoneNo'];
	echo "</td><td>";
	echo $row['Cover'];
	echo "</td></tr>";
}

echo "</table>";
?>
Any help appreciated.

Re: Numbers to yes/no

Posted: Mon Feb 27, 2012 12:01 pm
by temidayo
Do this at the cover point:

Code: Select all

echo "</td><td>";
        echo $row['Cover'] > 0 ? 'Yes' : 'No';
        echo "</td></tr>";

Re: Numbers to yes/no

Posted: Mon Feb 27, 2012 2:11 pm
by vampiro
Thank you... thought it would be something easy but couldnt see it

Re: Numbers to yes/no

Posted: Mon Feb 27, 2012 2:23 pm
by temidayo
You are welcome

Re: Numbers to yes/no

Posted: Thu Mar 01, 2012 10:52 am
by vampiro
Sorry to revive this thread.

My boss has now asked that this bit of code:

Code: Select all

echo $row['Cover'] > 0 ? 'Yes' : 'No';
Be colour coded so yes = green and no=black.

I have tried to sort it myself though verious avenues but have not succeeded, i try and learn these things my self and only post when i get stuck.

TIA

Re: Numbers to yes/no

Posted: Thu Mar 01, 2012 10:56 am
by Celauran
Use styled spans.

Code: Select all

echo $row['Cover'] > 0 ? '<span class="green">Yes</span>' : '<span class="black">No</span>';

Code: Select all

.green
{
    color: green;
}
.black
{
    color: black;
}