Reputation: 1
I have a table, which includes 16 car names. I want to change the font color and size if a car's name is found in a database.
This is my table:
And this is my PHP code for the first three cars:
<?php
$connection = mysql_connect($host,$user,$password);
if (!$connection){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cars", $connection);
$carname="car";
$squery = mysql_query("SELECT * FROM marks WHERE care_name=$car_name ");
echo"<div class='cars'>";
if(mysql_fetch_array($squery)) {
echo"<r><strong>". $row['car1'] ."<strong></r>";
}
else{
echo"<p>". $row['car1'] ."</p>";
}
echo"</div>";
echo"<div class='cars'>";
if(mysql_fetch_array($squery)) {
echo"<r><strong>". $row['car2'] ."<strong></r>";
}
else{
echo"<p>". $row['car2'] ."</p>";
}
echo"</div>";
echo"<div class='cars'>";
if(mysql_fetch_array($squery)) {
echo"<r><strong>". $row['car3'] ."<strong></r>";
}
else{
echo"<p>". $row['car3'] ."</p>";
}
echo"</div>";
?>
However, this doesn't work, it makes only on the first car (car1
).
Upvotes: 0
Views: 135
Reputation: 14312
You are using variables such as $row without assigning it a value first.
You need to save the return value from mysql_fetch_array
into the $row
variable e.g.
$row = mysql_fetch_array($squery);
if($row){
...
}
EDIT: On further examination of your code, it contains multiple basic errors such as
and there are probably many others. You really need to improve your basic understanding of coding practices (and possibly databases) before we can help further, as there are too many basic errors here that show a lack of understanding of what you are trying to do
Upvotes: 2