0

My database contains data as per the sample below. I would like to select the red highlighted row. Tried this query but doesn't display the row that I wanted. Any help is very much appreciated.

<?php

mysql_connect("localhost", "xxxxx", "xxxxx") or
die("Could not connect: " . mysql_error());
mysql_select_db("xxxxx");

$result = mysql_query("SELECT * FROM tablename");

$row = mysql_fetch_array($result);

if($row['imageurl'] == 0){
echo $row['email'];
}

mysql_free_result($result);

?>

Code above will return '[email protected]'.

enter image description here

6 Answers 6

1

Do you mean?:

SELECT * 
FROM tablename
WHERE imageurl IS NULL

If you want all results and test for NULL in PHP, see this question.

Sign up to request clarification or add additional context in comments.

Comments

1

Any reason on not doing it from query level?

"SELECT * From tablename where length(imageurl) = 0 or imageurl is null"

Comments

0

change this line :

if($row['imageurl'] == 0){

to :

if(empty($row['imageurl']) == true){

This will check if the imageurl is an empty string or null, as you want .

Comments

0

Probably the following statement solves your task:

SELECT * FROM TABLE WHERE imageurl IS NULL

Comments

0
if(empty($row['imageurl'])){
echo $row['email'];
}

Comments

0

If the field is just empty (and not NULL) try:

SELECT * FROM TABLE WHERE length(imageurl) = 0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.