cmattoon Posted April 16, 2010 Share Posted April 16, 2010 Hey all, I'm familiar with HTML/CSS, but brand new to PHP and such. I have built a MySQL database, and one of my queries brings up the following information Timestamp, ID#, Gender, Code # ID# can be just about anything (VARCHAR(50))... doesn't matter here.. Gender is (0)female, (1)male Code #'s are 0-4 (inclusive). Currently, I have a script that pulls the information and puts it into an HTML table. I want to highlight the rows (or even just the "code#" cells) by what the code is: if Code#=0, Black background, white text if Code#=1, Red background, white text if Code#=2, Yellow background, black text if Code#=3, Green background, white text if Code#=4, Blue background, white text I would imagine I could copy this code to highlight "gender" cells pink/blue. I just have no idea how to do this (i'd imagine an IF-THEN statement, but I'm having a hard time for some reason. Any ideas? Is it possible to sort this data by any of the above values (Time, ID, Gender, Code)?? Thanks!! Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/ Share on other sites More sharing options...
Deoctor Posted April 16, 2010 Share Posted April 16, 2010 have u wrote any code o try this?? Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1042876 Share on other sites More sharing options...
cmattoon Posted April 16, 2010 Author Share Posted April 16, 2010 I hate to sound lazy, but I literally started playing with PHP last night. I'm catching on, but I usually end up messing up my script when I try to do stuff. I've been borrowing from script libraries to learn, but just plain not sure how to go about this one....like I said, i *think* it can be done with an if-then, but not sure how to insert it into the code, or if it's even the best way. Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1042878 Share on other sites More sharing options...
cmattoon Posted April 16, 2010 Author Share Posted April 16, 2010 <?php include("access_db.inc"); $sql = mysql_query("SELECT * FROM patients"); echo "<table border=\"1\"><tr><td> TIMESTAMP </td><td>Tag Number</td><td>SEX</td><td>Tag Color</td><td>Location #</td></tr>"; while ($row = mysql_fetch_row($sql)) { echo "<tr><td>$row[8]</td><td>$row[0]</td><td>$row[5]</td><td>$row[11]</td><td>$row[17]</td></tr />"; } ?> This is what I have so far.... Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1042879 Share on other sites More sharing options...
oni-kun Posted April 16, 2010 Share Posted April 16, 2010 You should use mysql_fetch_assoc on the resource so you can call $row['gender'] if need be instead of by index. Your colours can be decided by a <span>/td tag handled obviously in each iteration of the loop. while ($row = mysql_fetch_assoc($sql)) { if($row['gender'] == 1) { $color="pink"; } else { $color="blue"; } echo "<tr><td style='background-color: $color;'>{$row['gender']}</td>..."; } Of course this is just a quick sample, How you implement it depends on what you simply wish. Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1042884 Share on other sites More sharing options...
cmattoon Posted April 16, 2010 Author Share Posted April 16, 2010 Thanks! When using the ' character... <td background style='color:red'> is it necessary to do the \' thing like you would for <color=\"red\">? Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1043155 Share on other sites More sharing options...
oni-kun Posted April 16, 2010 Share Posted April 16, 2010 Thanks! When using the ' character... <td background style='color:red'> is it necessary to do the \' thing like you would for <color=\"red\">? Single quotes can freely be used in double, And vice versa. You only need to escape them if they're going to be closing the opening quote. Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1043377 Share on other sites More sharing options...
cmattoon Posted April 17, 2010 Author Share Posted April 17, 2010 Ahh, okay. Thanks! Link to comment https://forums.phpfreaks.com/topic/198719-color-code-php-export-to-html/#findComment-1043843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.