Jump to content

How to say it (select ... from where .... and ...)


Recommended Posts

Hello dear friends,

 

If i've database table has named as info (id, name, number)

and i wanna say select from info where name must has value not empty

 

select * from info where name='xxxxwhatxxx'

 

i've tired $name and $1 and 1 but all not working how to say where name must has value and not empty

 

 

example if i've

(id, name, number) values (1, 'manal', '4')
(id, name, number) values (2, 'shimaa', '7')
(id, name, number) values (3, '', '3')

 

and i wanna say sellect from info where name has value so it shows me only data of id "1" and "2" only

 

thank you so much

it would helps me alot to improve myself

Link to comment
https://forums.phpfreaks.com/topic/219003-how-to-say-it-select-from-where-and/
Share on other sites

I think it depends on whether the ones you want to exclude have an empty string value or a null value - there is a diffrence.

 

Try this:

select * from info where name <> ''

 

Edit: Actually I don't think nulls will matter since they won't be included in the result set or the excluded set since you can't compare null to a non null value.

If its just blank and not null i belive

$result = mysql_query("SELECT * FROM info");
while ($row = mysql_fetch_array($result))
{
	if($row['name'] !='')
	{
		echo 'id:'. $row['id'] .' name:'. $row['name'] .'number:'. $row['number'] .'<br>';
	}
}

would work, Just tested it with different values in my database and it worked

@blink359's code will work, but it is not good programming. If you are not going to use the records where name!='' then don't pull them from the database. Otherwis,e you are just wasting system resources on the server.

 

I just did a test and the solution I provided works to exclude records that have a name value of NULL or an empty string:

$result = mysql_query("SELECT * FROM info");
while ($row = mysql_fetch_array($result))
{
    echo "id: {$row['id']}, name: {$row['name']}, number: {$row['number']}<br />\n";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.