I'm wondering if my code could be easier with a foreach loop. my code thusfar:
the purpose is to read the values in the MYSQL table, and if the anwser is "NEE" display the background color in RED. my code works but it is very long..
$connection = mysql_connect('localhost', 'root', ''); //The Blank string is
the password
mysql_select_db('heijsDB');
$query = "SELECT * FROM hygieneaanvoer"; //You don't need a ; like you do in
SQL
$result = mysql_query($query);
//List the Columns for the Report
if(! $result ) {
die('Could display data: ' . mysql_error());
}
echo "<table border='1' class='w3-panel'>
<fieldset>hygiëne/GMP aduit Aanvoer</fieldset>
<tr>
<th>Datum</th>
<th>Controleur</th>
<th>controleur</th>
<th>Revisie</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
<th>8</th>
<th>9</th>
<th>10</th>
<th>11</th>
<th>12</th>
<th>13</th>
<th>14</th>
<th>15</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['controleur'] . "</td>";
echo "<td>" . $row['codering'] . "</td>";
echo "<td>" . $row['revisie'] . "</td>";
if($row['q1']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q1']."</td>";
else echo "<td>".$row['q1']."</td>";
if($row['q2']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q2']."</td>";
else echo "<td>".$row['q2']."</td>";
if($row['q3']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q3']."</td>";
else echo "<td>".$row['q3']."</td>";
if($row['q4']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q4']."</td>";
else echo "<td>".$row['q4']."</td>";
if($row['q5']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q5']."</td>";
else echo "<td>".$row['q5']."</td>";
if($row['q6']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q6']."</td>";
else echo "<td>".$row['q6']."</td>";
if($row['q7']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q7']."</td>";
else echo "<td>".$row['q7']."</td>";
if($row['q8']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q8']."</td>";
else echo "<td>".$row['q8']."</td>";
if($row['q9']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q9']."</td>";
else echo "<td>".$row['q9']."</td>";
if($row['q10']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q10']."</td>";
else echo "<td>".$row['q10']."</td>";
if($row['q11']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q11']."</td>";
else echo "<td>".$row['q11']."</td>";
if($row['q12']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q12']."</td>";
else echo "<td>".$row['q12']."</td>";
if($row['q13']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q13']."</td>";
else echo "<td>".$row['q13']."</td>";
if($row['q14']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q14']."</td>";
else echo "<td>".$row['q14']."</td>";
if($row['q15']=='NEE') // [val1] can be 'approved'
echo "<td style='background-color: #e21010;'>".$row['q15']."</td>";
else echo "<td>".$row['q15']."</td>";
echo "</tr>";
}
echo "</table>";
?>
Here is solution
$result = mysql_query("SELECT * FROM hygieneaanvoer")or die('Could display data: ' . mysql_error());;
echo "<table border='1' class='w3-panel'>
<fieldset>hygiëne/GMP aduit Aanvoer</fieldset>
<tr>
<th>Datum</th>
<th>Controleur</th>
<th>controleur</th>
<th>Revisie</th>";
for ($i=1;$i<=15;$i++){
echo '<th>'.$i.'</th>';
}
echo "</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['controleur'] . "</td>";
echo "<td>" . $row['codering'] . "</td>";
echo "<td>" . $row['revisie'] . "</td>";
for ($j=1;$j<=15;$j++){
echo "<td ".(($row['q'.$j] == 'NEE') ? "style='background-color: #e21010;'" : "" ).">".$row['q'.$j]."</td>";
}
echo "</tr>";
}
echo "</table>";
?>
What you could do, is just create a single variable that you'd use for setting the style of all rows:
while($row = mysql_fetch_array($result))
{
$style_string = "";
if($row['q1']=='NEE') {
$style_string = "style='background-color: #e21010;'";
}
echo "<tr>";
echo "<td>" . $row['datum'] . "</td>";
echo "<td>" . $row['controleur'] . "</td>";
echo "<td>" . $row['codering'] . "</td>";
echo "<td>" . $row['revisie'] . "</td>";
echo "<td " . $style_string . ">" . $row['q1'] . "</td>";
echo "<td " . $style_string . ">" . $row['q2'] . "</td>";
echo "<td " . $style_string . ">" . $row['q3'] . "</td>";
echo "<td " . $style_string . ">" . $row['q4'] . "</td>";
echo "<td " . $style_string . ">" . $row['q5'] . "</td>";
echo "<td " . $style_string . ">" . $row['q6'] . "</td>";
echo "<td " . $style_string . ">" . $row['q7'] . "</td>";
echo "<td " . $style_string . ">" . $row['q8'] . "</td>";
echo "<td " . $style_string . ">" . $row['q9'] . "</td>";
echo "<td " . $style_string . ">" . $row['q10'] . "</td>";
echo "<td " . $style_string . ">" . $row['q11'] . "</td>";
echo "<td " . $style_string . ">" . $row['q12'] . "</td>";
echo "<td " . $style_string . ">" . $row['q13'] . "</td>";
echo "<td " . $style_string . ">" . $row['q14'] . "</td>";
echo "<td " . $style_string . ">" . $row['q15']. "</td>";
echo "</tr>";
}
(Or just set the background color of the <tr>)
Best of luck!
You can simply add the class to the td like this
echo "<td class='". $row['q15'] . "'>".$row['q15']."</td>";
Add css like this
.NEE {background-color: #e21010;}
Related
Here's my code:
foreach ($grabdata as $row) {
echo "<tr>";
echo "<td class='editableColumns'>" . $row['EmployeeName'] . "</td>";
echo "<td class='editableColumns'>" . $row['EmployeeID'] . "</td>";
echo "<td class='editableColumns'>" . $row['ContactNumber'] . "</td>";
echo "<td class='editableColumns'>" . $row['Gender'] . "</td>";
echo "<td class='editableColumns'>" . $row['Email'] . "</td>";
echo "<td class='editableColumns'>" . $row['DOB'] . "</td>";
echo "<td class='editableColumns'>" . $row['AreaOfExpertise'] . "</td>";
echo "<td class='editableColumns'>" . $row['State'] . "</td>";
echo "<td class='editableColumns'>" . $row['Status'] . "</td>";
echo "<td><input class='editValues' type='button' value='Edit'></td>";
echo "</tr>";
echo "</table>";
}
I expected all data in the db to be displayed in a table. Unfortunately only the first result appears in the table and the following appear without the table. What am I doing wrong?
You need to put the </table>-Tag outside of the foreach loop:
echo "<table>";
foreach ($grabdata as $row) {
echo "<tr>";
echo "<td class='editableColumns'>" . $row['EmployeeName'] . "</td>";
echo "<td class='editableColumns'>" . $row['EmployeeID'] . "</td>";
echo "<td class='editableColumns'>" . $row['ContactNumber'] . "</td>";
echo "<td class='editableColumns'>" . $row['Gender'] . "</td>";
echo "<td class='editableColumns'>" . $row['Email'] . "</td>";
echo "<td class='editableColumns'>" . $row['DOB'] . "</td>";
echo "<td class='editableColumns'>" . $row['AreaOfExpertise'] . "</td>";
echo "<td class='editableColumns'>" . $row['State'] . "</td>";
echo "<td class='editableColumns'>" . $row['Status'] . "</td>";
echo "<td><input class='editValues' type='button' value='Edit'></td>";
echo "</tr>";
}
echo "</table>";
<?php
{
echo "</br>";
echo "</br>";
echo "<table border='1'> <tr>";
while ($row1=mysql_fetch_array($result1)){
echo "<td><strong>" . $_POST['card_no']. "</strong></td>";
echo "<td><strong>" . $row1['lname']. "</strong></td>";
}
"</tr>";
echo "<tr><td><strong> Total Incentive: </strong></td><td><strong> Rs." $TotalIncentive " </strong> </td></tr>";
//i want to show Total Incentive Value above table "$TotalIncentive". pls see attached image for more clarification.
echo "<table border='1' width='auto'>
<tr>
<th>Tid</th>
<th>Depart</th>
<th>Sub Depart</th>
<th>EARN</th>
<th>Eff</th>
<th> Group Eff </th>
<th>Date</th>
<th>Incentive</th>
</tr>";
//$sql=Query not show here becz its very large Query
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td bgcolor='#FFFFF'>" . $row['t_id'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['dep_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['subdep_code']." ".$row['type_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['TER']. "</td>";
echo "<td bgcolor='#00FF33'>" . round(($row['TER']/570)*$pre). "%</td>";
echo "<td bgcolor='#FFFF00'>" . round($row['geff1']) . "%</td>";
echo "<td bgcolor='#FFFFF'>" . $row['tdate'] . "</td>";
if($row['geff1']>=105){
$inc=(300*($row['TER']/570)*$pre)/105;
}elseif($row['geff1']>=100){
$inc=(275*($row['TER']/570)*$pre)/100;
}elseif($row['geff1']>=95){
$inc=(240*($row['TER']/570)*$pre)/95;
}elseif($row['geff1']>=90){
$inc=(200*($row['TER']/570)*$pre)/90;
}elseif($row['geff1']>=85){
$inc=(160*($row['TER']/570)*$pre)/85;
}elseif($row['geff1']>=80){
$inc=(120*($row['TER']/570)*$pre)/80;
}elseif($row['geff1']>=75){
$inc=(90*($row['TER']/570)*$pre)/75;
}elseif($row['geff1']>=70){
$inc=(60*($row['TER']/570)*$pre)/70;
}elseif($row['geff1']>=65){
$inc=(30*($row['TER']/570)*$pre)/65;
}elseif($row['geff1']<65){
$inc=0;
}
echo "<td ><strong>Rs.".round($inc,2);"</strong></td>";
echo "</tr>";
//Total Incentive Should be SUM(round($inc,2))
}
echo "</table>";
mysql_close($con);
}
//I want to Show "Total Incentive" Value in the place that i mention in my Image
?>
update your while loop as below & echo $totalInc at the end of this while() loop
<?php
$totalInc = 0; //added this variable
while ($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td bgcolor='#FFFFF'>" . $row['t_id'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['dep_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['subdep_code']." ".$row['type_code'] . "</td>";
echo "<td bgcolor='#FFFFF'>" . $row['TER']. "</td>";
echo "<td bgcolor='#00FF33'>" . round(($row['TER']/570)*$pre). "%</td>";
echo "<td bgcolor='#FFFF00'>" . round($row['geff1']) . "%</td>";
echo "<td bgcolor='#FFFFF'>" . $row['tdate'] . "</td>";
if($row['geff1']>=105){
$inc=(300*($row['TER']/570)*$pre)/105;
}elseif($row['geff1']>=100){
$inc=(275*($row['TER']/570)*$pre)/100;
}elseif($row['geff1']>=95){
$inc=(240*($row['TER']/570)*$pre)/95;
}elseif($row['geff1']>=90){
$inc=(200*($row['TER']/570)*$pre)/90;
}elseif($row['geff1']>=85){
$inc=(160*($row['TER']/570)*$pre)/85;
}elseif($row['geff1']>=80){
$inc=(120*($row['TER']/570)*$pre)/80;
}elseif($row['geff1']>=75){
$inc=(90*($row['TER']/570)*$pre)/75;
}elseif($row['geff1']>=70){
$inc=(60*($row['TER']/570)*$pre)/70;
}elseif($row['geff1']>=65){
$inc=(30*($row['TER']/570)*$pre)/65;
}elseif($row['geff1']<65){
$inc=0;
}
$totalInc = $totalInc + $inc; //set value to this variable
echo "<td ><strong>Rs.".round($inc,2);"</strong></td>";
echo "</tr>";
I am trying to add a column before my first column that starts numbering each record, starting from 1. I was trying to add autoincrement to this line echo "" . $row['ss'] . "";, but that does not seem to want to work. Any ideas how to do this?
My code looks like this:
$result = mysqli_query($con,"SELECT * FROM `results` WHERE Event='100' AND Gender='M' ORDER BY Performance ASC");
echo "<table border='0'>
<tr>
<th align='left'>Pos</th>
<th align='left'>Event</th>
<th>Performance</th>
<th>Wind</th>
<th>Place</th>
<th align='left'>Name</th>
<th align='left'>Surname</th>
<th>Age</th>
<th>Team</th>
<th>Meet</th>
<th>Date</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ss'] . "</td>";
echo "<td>" . $row['Event'] . "</td>";
echo "<td>" . $row['Performance'] . "</td>";
echo "<td>" . $row['Wind'] . "</td>";
echo "<td>" . $row['Pos'] . "</td>";
echo "<td width='100' align='left'>" . $row['Surname'] . "</td>";
echo "<td Width='100'>" . $row['Name'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Team'] . "</td>";
echo "<td>" . $row['Meet'] . "</td>";
echo "<td>" . $row['Date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Add this line in header
<th align='left'>#</th>
And here php code
$count = 1;
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $count . "</td>";
echo "<td>" . $row['ss'] . "</td>";
echo "<td>" . $row['Event'] . "</td>";
echo "<td>" . $row['Performance'] . "</td>";
echo "<td>" . $row['Wind'] . "</td>";
echo "<td>" . $row['Pos'] . "</td>";
echo "<td width='100' align='left'>" . $row['Surname'] . "</td>";
echo "<td Width='100'>" . $row['Name'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Team'] . "</td>";
echo "<td>" . $row['Meet'] . "</td>";
echo "<td>" . $row['Date'] . "</td>";
echo "</tr>";
//other code
$count=$count+1;
}
A better solution would be to use a variable counter to "number" your rows:
$counter = 1;
while($row = mysqli_fetch_array($result))
echo "<td>" . $counter . "</td>";
$counter++;
}
This is the right way to do it since if that ss column is the mysql auto increment, then your rows will not be numbered by the SORT but rather from the order in which they were inserted into the database regardless of any sorting you apply.
Try to change fetch_array with fetch_assoc
while($row = mysql_fetch_array($query2testing)) {
echo "<tr>";
echo "<td><center>$i</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['matricNo'] . "</td>";
echo "<td><center>" . $row['LC'] . "</td>";
echo "<td>" . $row['Code'] . "</td>";
echo "<td>" . $row['Subject'] . "</td>";
if(!empty($row['Assignment1'])) {
echo "<td><center><font color='red'>" . $row['Assignment1'] . "</td>";
}
echo "<td><center>" . $row['Quiz'] . "</td>";
echo "<td><center>" . $row['Participation'] . "</td>";
echo "<td><center>" . $row['Attendance'] . "</td>";
echo "<td><center>" . $row['Exam'] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
This is my simple code.
How to make my column red if assigment1 is null
and assigment1 is not null to blue
style="background-color:red;" and background-color:blue; is possibly what you are looking for. You did not specify how the columns should be painted so you might have to adjust this.
Just insert this to your columns or rows you want to apply the color:
e.g. for a row (guess this is your header):
echo "<td style="background-color:red;"><center><font color='blue'>" . $row['Assignment1'] . "</td>";
use this in the first echo
echo "<tr style='background-color:" . (($row['Assignment1'] === NULL) ? "red" : "blue") . "'>";
Please replace your code with below code:
while($row = mysql_fetch_array($query2testing))
{
echo "<tr>";
echo "<td><center>$i</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['matricNo'] . "</td>";
echo "<td><center>" . $row['LC'] . "</td>";
echo "<td>" . $row['Code'] . "</td>";
echo "<td>" . $row['Subject'] . "</td>";
if(!empty($row['Assignment1']))
{
echo "<td><center><font color='blue'>" . $row['Assignment1'] . "</td>";
}
else
{
echo "<td><center><font color='red'>" . $row['Assignment1'] . "</td>";
}
echo "<td><center>" . $row['Quiz'] . "</td>";
echo "<td><center>" . $row['Participation'] . "</td>";
echo "<td><center>" . $row['Attendance'] . "</td>";
echo "<td><center>" . $row['Exam'] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
Try this:
while($row = mysql_fetch_array($query2testing))
{
echo "<tr>";
echo "<td><center>$i</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['matricNo'] . "</td>";
echo "<td><center>" . $row['LC'] . "</td>";
echo "<td>" . $row['Code'] . "</td>";
echo "<td>" . $row['Subject'] . "</td>";
if(!empty($row['Assignment1']))
{
echo "<td><center><font color='blue'>" . $row['Assignment1'] . "</td>";
}
else {
echo "<td><center><font color='red'>" . $row['Assignment1'] . "</td>";
}
echo "<td><center>" . $row['Quiz'] . "</td>";
echo "<td><center>" . $row['Participation'] . "</td>";
echo "<td><center>" . $row['Attendance'] . "</td>";
echo "<td><center>" . $row['Exam'] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
Three (3) things:
Let's convert your MySQL to MySQLi. Just put else on to your if(empty($row['Assignment1'])). AND Border Color is what you want to change color, right?
<html>
<body>
<?php
$con=mysqli_connect("host","username","password","database");
if(mysqli_connect_errno()){
echo "Error".mysqli_connect_error();
}
$i=1;
$query2testing=mysqli_query($con,"SELECT * FROM yourTable");
echo "<table>";
while($row = mysqli_fetch_array($query2testing))
{
echo "<tr>";
echo "<td><center>$i</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['matricNo'] . "</td>";
echo "<td><center>" . $row['LC'] . "</td>";
echo "<td>" . $row['Code'] . "</td>";
echo "<td>" . $row['Subject'] . "</td>";
if(empty($row['Assignment1']))
{
echo "<td style='border: 1px solid red;'><center>" .$row['Assignment1'] . "</td>"; /* YOU WANT THE BORDER TO CHANGE COLOR, RIGHT? */
}
else {
echo "<td style='border: 1px solid blue;'><center>" .$row['Assignment1']."</td>"; /* YOU WANT THE BORDER TO CHANGE COLOR, RIGHT? */
}
echo "<td><center>" . $row['Quiz'] . "</td>";
echo "<td><center>" . $row['Participation'] . "</td>";
echo "<td><center>" . $row['Attendance'] . "</td>";
echo "<td><center>" . $row['Exam'] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";
?>
</body>
</html>
I have a simple crud application where i am listing certain information . i need to create a filter on the basis of category but am getting an error.
I get the error:
Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql_real_escape_string()' at line 1 in C:\wamp\www\media universe\list.php on line 6
Also tell me if I am going wrong with the filtering.
<?php
include('config.php');
$result = mysql_query("SELECT * FROM `media_universe`") or trigger_error(mysql_error());
if (isset($_POST['submitted_filter'])) {
$filter_category= $_POST[category_filter];
$result = mysql_query("SELECT * FROM `media_universe` where category= '%s',mysql_real_escape_string($filter_category)") or trigger_error(mysql_error());
}
?>
<form action='' method='POST'>
<p><b>Category:</b> <select name="category">
<option>All</option>
<option>Lifestyle</option>
<option>Automobiles</option>
<option>FoodandBeverage</option>
<option>Health</option>
<option>IT</option>
<option>Telecom</option>
<option>EntertainmentandCelebrity</option>
<option>Education</option>
<option>BankingInvestmentandInsurance</option>
<option>Travel</option>
<option>Sports</option>
<option>Parenting</option>
<option>ConsumerElectronics</option>
<option>RealtyandLogistics</option>
<option>CauseLed</option>
</select>
<p><input type='submit' value='Filter' /><input type='hidden' value='1' name='submitted_filter' />
</form>
<?php
include('config.php');
echo "<table border=1 >";
echo "<tr>";
echo "<td><b>Id</b></td>";
echo "<td><b>Category</b></td>";
echo "<td><b>Coursedetail</b></td>";
echo "<td><b>Nameofblog</b></td>";
echo "<td><b>Blogdescription</b></td>";
echo "<td><b>Nameofsocialnetworkiforkfac</b></td>";
echo "<td><b>Nameofsocialnetworkifnotorkfac</b></td>";
echo "<td><b>Nameofsocnetcommunity</b></td>";
echo "<td><b>Numberofmembersinsocnetcommunity</b></td>";
echo "<td><b>Nameofdiscussionforum</b></td>";
echo "<td><b>Descriptionofdiscussionforum</b></td>";
echo "<td><b>NameofQNAsite</b></td>";
echo "<td><b>Nameofnewssite</b></td>";
echo "<td><b>DescriptionofQNAsite</b></td>";
echo "</tr>";
while($row = mysql_fetch_array($result)){
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); }
echo "<tr>";
echo "<td valign='top'>" . nl2br( $row['id']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['category']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['coursedetail']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofblog']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['blogdescription']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofsocialnetworkiforkfac']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofsocialnetworkifnotorkfac']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofsocnetcommunity']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['numberofmembersinsocnetcommunity']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofdiscussionforum']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['descriptionofdiscussionforum']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofQNAsite']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['nameofnewssite']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['descriptionofQNAsite']) . "</td>";
echo "<td valign='top'><a href=edit.php?id={$row['id']}>Edit</a></td><td><a href=delete.php?id={$row['id']}>Delete</a></td> ";
echo "</tr>";
}
echo "</table>";
echo "<a href=new.php>New Row</a>";
?>
Your error, as the error message states, is here:
"SELECT * FROM `media_universe` where category='%s',mysql_real_escape_string($filter_category)"
You're constructing the string incorrectly. You were probably thinking of using sprintf, but didn't. This should do it:
"SELECT * FROM `media_universe` where category='" . mysql_real_escape_string($filter_category) . "'"