I get no errors but no table is displayed, I know its not on prepared statements but there is no interaction its just a display so there is no chance of SQL injection
what Am I missing
Hello I have edited the long version
<?php
echo "<table border='10' style='border-collapse: collapse;border-color: #0099FF;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='200' align='center'>NAme</td><td width='200' align='center'>Headhot</td><td width='200' align='center'>Date</td><td width='200' align='center'>Age</td>";
echo "</tr>";
include("dbopent.php");
$result = mysql_query("
SELECT N, Limg, Lpage, F, Age
FROM (
SELECT N, Limg, Lpage, F, Age
FROM (
SELECT N, Limg, Lpage, F, CURDATE( ) , (
YEAR( CURDATE( ) ) - YEAR( F )
) - ( RIGHT( CURDATE( ) , 5 ) < RIGHT( F, 5 ) ) AS Age
FROM ACT)alias
WHERE Age BETWEEN 30 AND 39)ALIAS
");
while($row=mysql_fetch_array($result))
$color="1";
{
if($color==1){
echo "<tr bgcolor='#000000'>";
echo "<td align='center' width='10'>" . $row['N'] . "</td>";
echo "<td align='center' width='10'>" . "<a href=\"{$row['Lpage']}\"><img src=\"{$row['Limg']}\">" . "</td>";
echo "<td align='center' width='10'>" . $row['F'] . "</td>";
echo "<td align='center' width='10'>" . $row['Age'] . "</td>";
echo "</tr>";
}
else {
echo "<tr bgcolor='#FFFFFF'>";
echo "<td align='center' width='10'>" . $row['N'] . "</td>";
echo "<td align='center' width='10'>" . "<a href=\"{$row['Lpage']}\"><img src=\"{$row['Limg']}\">" . "</td>";
echo "<td align='center' width='10'>" . $row['F'] . "</td>";
echo "<td align='center' width='10'>" . $row['Age'] . "</td>";
echo "</tr>";
$color="1";
}
}
echo '</table>';
?>
You write "SELECT SELECT".
P.S. And it is bad practice to mix PHP and HTML code. Look towards the MVC.
First issue is that you don't have the FROM clause in your SQL statement. A valid query is as follows:
SELECT * FROM Table WHERE condition = something
.
You can define integers without the quotes: $color = "1";
has to be $color = 1;
Also, you are supposed to add it after the open curly bracket.
while($row=mysql_fetch_array($result))
{
$color = 1;
// rest of the code
}
Also please put error_reporting(E_ALL);
on top of your script after the begin tag so it will display any errors on the screen.
You should also explain your issue in a better way, it's unclear what you want.
Define color to 1... increase on each loop. do a modulus base 2 to see if there is a remainder and if there is it's odd then otherwise it's even.
$color = 1;
while($row=mysql_fetch_array($result))
{
$color++;
if ($color % 2 == 0){
$outputColor = "#7b7b7b";
} else {
$outputColor = "#fff";
}
echo "<tr bgcolor='".$outputColor."'>";
echo "<td align='center' width='10'>" . $row['Name'] . "</td>";
echo "<td align='center' width='10'>" . "<a href=\"{$row['page']}\"><img src=\"{$row['img']}\">" . "</td>";
echo "<td align='center' width='10'>" . $row['date'] . "</td>";
echo "<td align='center' width='10'>" . $row['Age'] . "</td>";
echo "</tr>";
}
this doesn't repeat all that code that is unnecessary.. rather define the color and output it once...
However you should REALLY be using a css style since i didn't think all browsers support a TR with a background color.
Something like echo "<tr class='".$outputColor."'>";
and instead setting $outputColor to 'odd' or 'even'
then .odd td {background-color:#7b7b7b}
.even td {background-color:#fff}