Reputation: 85
In my code, it should show the message if the value of Enabled in the table BannerStatus is true, but it does not show it at all this is my code
<?php
error_reporting(-1);
mysql_connect('localhost', 'username', 'password');
mysql_select_db("induadmi_db");
$message = mysql_query("SELECT `Message` FROM `Banner`");
$value = mysql_query("SELECT `Enabled` FROM `BannerStatus`");
while($msg = mysql_fetch_array($message))
while($value2 = mysql_fetch_array($value))
{
if ($value2['Enabled'] == "true") {
echo' <div id="emsg" class="emsg_inner emsgB">';
echo $msg['Message'], "</div>";
}
}
?>
Thanks, all help is appreciated greatly!
Upvotes: 1
Views: 50
Reputation: 2783
Your code fetches the first "message" and then loops through the "values". Is this what you want?
You will not get any values for the next message as the "values" query is already at the last record!
How are these two tables related? Can you join the two tables in one query?
Upvotes: 1
Reputation: 8960
1) Missing brackets {
and ]
2) Change this - echo' <div id="emsg" class="emsg_inner emsgB">';
Try replacing below code -
while($msg = mysql_fetch_array($message))
{
while($value2 = mysql_fetch_array($value))
{
if ($value2['Enabled'] == "true")
{
echo "<div id='emsg' class='emsg_inner emsgB'>";
echo $msg['Message']. "</div>";
}
}
}
Upvotes: 0
Reputation: 44581
Missing single quote :
mysql_connect('localhost', 'username', 'password');
And it is not a very good practice to use mysql
functions, look forward using mysqli
or PDO
.
Also:
while($msg = mysql_fetch_array($message)){
while($value2 = mysql_fetch_array($value)){
if ($value2['Enabled'] == 'true') {
echo "<div id=\"emsg\" class=\"emsg_inner emsgB\">{$msg['Message']}</div>";
}
}
}
Upvotes: 2