remove black block (css,php) - php

i have this code for result page:
http://pastebin.com/XK3hdNYY
and this css
http://pastebin.com/rs22p4px
but i have a black block that has nothing to do with css.
For example, when the code is this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "</tr>";
i have this table output
when i change the code like this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo "<td width='auto'>". $row[3] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "</tr>";
I have this output:
and when i change like this
echo "<tr>";
echo "<td width='auto' bgcolor=”#FF0000 ″>" . " ". "<b>" . $i . " ". "<b/>". "</td>";
echo "<td width='auto'>" . " " . $row[1] . " " . "</td>";
echo "<td width='auto'>". $row[2] . "</td>";
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
echo "<td width='auto'>". $row[3] . "</td>";
echo "</tr>";
my output:
I want remove these black block an and the column too. In the third case, it seems that the column has lost its borders and lines?

Looks like you have an HTML syntax error:
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div><td>';
Should be:
echo '<td><span class="spoiler-label">'.$row[1].'</span><div class="spoiler-content" style="display: none"><br>'.$row[3].'</div></td>';
See the closing </td> at the end of each line. You're opening a new column mistakenly.
A new column without a <th> to represent it will default to a blank column like this.

Related

How to create a multiple hyperlink in in single php line

I have tried below code; as you can see in bold line i want to add two hyperlink but i am not getting results.I want to create a variable hyperlink.
<?php
echo "<!DOCTYPE html>";
echo "<html>";
echo "<title> disorders </title>";
echo "<body>";
include ('menu.php');
echo "<br>";
echo "<br>";
$disorder = $_GET ['disorder'];
$sql_disorder= "SELECT * FROM `disorders raw datasets` WHERE `Name of disorder` = '$disorder' ";
if ($result_disorder = mysqli_query($conn, $sql_disorder));
{
echo "<table border='1' cellpadding='2' cellspacing='1'> ";
echo "<tr>";
echo "<th>Accession ID</th>";
echo "<th>Title</th>";
echo "<th>Abstract</th>";
echo "<th>Tissue type</th>";
echo "<th>PMID</th>";
echo "<th>Other information</th>";
echo "</tr>";
while($row_disorder = mysqli_fetch_array($result_disorder))
{
echo "<tr>";
**echo "<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc= href='https://www.ebi.ac.uk/arrayexpress/experiments/" . $row_disorder['Accession ID'] . " ' ' >" . $row_disorder['Accession ID'] . "</a> </td>";**
echo "<td>" . $row_disorder['Title'] . " </td>";
echo "<td>" . $row_disorder['Abstract'] . "</td>";
echo "<td>" . $row_disorder['Tissue type'] . " </td>";
echo "<td><a href='https://www.ncbi.nlm.nih.gov/pubmed/" . $row_disorder['PMID'] . " '>" . $row_disorder['PMID'] . "</a></td>";
echo "<td><a href='disorder_info.php?" . $row_disorder['Other information'] . " ' >" . $row_disorder['Other information'] . "</a></td>";
echo "</tr>";
}
echo "</table>";
}
echo "</body>";
echo "</html>";
?>
I don't know why you are using two href in a single tag, that does not support by any dom. Although replace your code with the following line.
echo "
<td><a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=' href='https://www.ebi.ac.uk/arrayexpress/experiments/' " . $row_disorder['Accession ID'] . " ' '>" . $row_disorder['Accession ID'] . "</a> </td>";
You will have to use urlencode for it to work
$queryString = urlencode("href='https://www.ebi.ac.uk/arrayexpress/experiments/{$row_disorder['Accession ID']}'");
echo "
<td>
<a href='https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=$queryString'>
{$row_disorder['Accession ID']}
</a>
</td>";

Only single row displayed in table

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>";

foreach loop highlight cells from database

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;}

borderColor if null value

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>

HTML through PHP not taking a CSS rule

Is there any reason that the following code and syle wouldn't work? The only problem is that I can't get the text to change color, it stays black, which would be fine but the background color is black. I know it's there because I can highlight the text with the cursor and it's there in the table. Here's my code fragment.
This is from the index.php page.
while($row=mysqli_fetch_array($result))
{
echo "<tr id= "Data'" class='"Data'">";
echo "<td id= " cell ">" . $row['Name'] . "</td>";
echo "<td id= " cell ">" . $row['Subject'] . "</td>";
echo "<td id= " cell ">" . $row['Date'] . "</td>";
echo "<td id= " cell ">" . $row['Source'] . "</td>";
echo "<td id= " cell ">" . $row['Comment'] . "</td>";
echo "</tr>";
}
here's the css rule that SHOULD be applied.....but isn't.
#Cell{
border-style: solid;
border-color: black;
border-width: 1px;
color: white;
<td id= " cell "> is not equivalent to <td id="cell"> because HTML does not recursively evaluate itself. So the former tag is invalid gobbledegook without an id. You also cannot give the same id to more than one element.
Why your are using " cell "
Here is correct code
while($row=mysqli_fetch_array($result))
{
echo "<tr id=\"Data\" class=\"Data\">";
echo "<td id=\"cell\">" . $row['Name'] . "</td>";
echo "<td id=\"cell\">" . $row['Subject'] . "</td>";
echo "<td id=\"cell\">" . $row['Date'] . "</td>";
echo "<td id=\"cell\">" . $row['Source'] . "</td>";
echo "<td id=\"cell\">" . $row['Comment'] . "</td>";
echo "</tr>";
}

Categories