Jump to content

No value from mysql_fetch_array


porta325

Recommended Posts

Hey guys, i was wondering... if i have something like this

 

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

while ($row = mysql_fetch_array($result)){

$some = $row['some']

}

 

how do i get something like;

 

if ($some == false){

echo "nothing";

}

else

{

echo "something";

}

 

The question is how can i return false is the array contains nothing ?

Link to comment
https://forums.phpfreaks.com/topic/102544-no-value-from-mysql_fetch_array/
Share on other sites

That means $row['some'] does not exist. There's no array key called "some". Make sure that your table actually has a column name "some" and it contains a boolean value if you want to do

if ($some == false)

.

 

If you want to check if that value exists, you can use

if (empty($some))

Should have worked but this is stupid. Empty takes all kind of things from empty strings to declared variables with no value but still it wont work.

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

while ($row = mysql_fetch_array($result)){

$col1 = $row['col1'];

if (empty($col1)){

echo "nothing";

}

else

{

echo "something";

}

}

 

Still displays "something" if table not empty and nothing if table empty.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.