Note that there are some explanatory texts on larger screens.

plurals
  1. POSet background color of cells based on MySQL query output
    text
    copied!<p>I am new to PHP and trying to learn enough to do some basic functions. I've been able to create a table for my users to edit themselves, and redisplay but I've come across a question. Using the script below, users can input their skill level for various products. I wanted to be able to highlight each cell in which they input "0" or blank. User's input will be between 0-5 (or blank if they haven't filled it in yet).</p> <p>This is all being done on my localhost so I'll admit all the security measures are not quite there. </p> <p>I've read a lot of posts and tried to figure it out myself, but I'm doing something fundamentally wrong I believe. </p> <p>Any assistance on this would be greatly appreciated. I've been known to buy a beer (via paypal) for those who help me with coding :)</p> <p>Here is my existing code for printing out the results of the database:</p> <pre><code>&lt;?php //This will connect to the database in order to begin this page mysql_connect("localhost", "root", "time2start") or die (mysql_error()); //Now we will select the database we need to talk to mysql_select_db("joomla_dev_15") or die (mysql_error()); $query = "SELECT * FROM enterprise_storage WHERE id=1"; $result = mysql_query($query) or die (mysql_error()); echo "&lt;table border='1'&gt;"; echo "$row"; echo "&lt;tr&gt; &lt;th&gt;Product&lt;/th&gt; &lt;th&gt;Wayne Beeg&lt;/th&gt; &lt;th&gt;Paul Hamke&lt;/th&gt; &lt;th&gt;Steve Jaczyk&lt;/th&gt; &lt;th&gt;David Jontow&lt;/th&gt; &lt;th&gt;Ed MacDonald&lt;/th&gt; &lt;th&gt;Michael Munozcano&lt;/th&gt; &lt;th&gt;Ron Shaffer&lt;/th&gt; &lt;th&gt;Luke Soares&lt;/th&gt; &lt;th&gt;Josh Wenger&lt;/th&gt; &lt;/tr&gt;"; // 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 "&lt;tr&gt;&lt;td&gt;"; echo $row['model']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['beeg']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['hamke']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['jaczyk']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['jontow']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['macdonald']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['munozcano']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['shaffer']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['soares']; echo "&lt;/td&gt;&lt;td&gt;"; echo $row['wenger']; echo "&lt;/td&gt;&lt;/tr&gt;"; } echo "&lt;/table&gt;"; ?&gt; &lt;FORM&gt; &lt;INPUT TYPE="BUTTON" VALUE="Return to the Home Page" ONCLICK="window.location.href='http://localhost/~user/joomla15/custom/skilldisplay.php'"&gt; &lt;/FORM&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload