How script php can check If there is an empty column in my database in Table the_ad Where column image_link For now my script can not check if there is an empty column What did I do wrong Here is my full code
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("test",$dbhandle)
or die("Could not select test");
//fetch tha data from the database
$result_image_link = mysql_query("SELECT image_link FROM test. the_ad");
while ($row_image = mysql_fetch_array($result_image_link)) {
if (empty($result_image_link)) {
echo "no image_link";
}
else
if (isset($result_image_link)) {
echo "PIC=".$row_image{'image_link'}."<br>";
}
}
mysql_close($dbhandle);
?>
I see the list of column likethis
Why column one and two Not show the message
Thanks to anyone who can help
Use this query: SELECT image_link FROM test WHERE image_link != NULL
Your check is concerning the whole amount of results. Only if there are no results returned from your query, the empty
function will return false. You can use the query above or change your if statement to this !empty($row_image['image_link'])
.
You can add SQL statement WHERE `image` != ''
$result_image_link = mysql_query("
SELECT `image`
FROM `table`
WHERE `image` != ''
");
while($row_image = mysql_fetch_array($result_image_link))
{
echo "PIC=" . $row_image['image'] . "<br/>";
}
OR
while ($row_image = mysql_fetch_array($result_image_link))
{
echo (isset($row_image['image']) AND $row_image['image'] != '')
? "PIC=" . $row_image['image'] . "<br/>"
: 'no picture <br/>';
}