PDA

View Full Version : Resolved Get data from DB using WHERE


Big-Gaz
08-08-2009, 02:25 PM
Hi,

I am wanting to use a WHERE tag in my MySQL line to get something, but not where it blank

So for example if

BackgroundFilename = abc.png
or
BackgroundFilename = abcd.jpg
or
BackgroundFilename = abcde.gif
etc..., regardless or extensions.

I want MySQL to get these, I am not sure if the WHERE tag is right



The below code works if BackgroundFilename is Blank/Empty

$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM USERNAME_custom WHERE BackgroundFilename=""';

abduraooft
08-08-2009, 02:55 PM
$sql = 'SELECT field_name FROM table_name WHERE BackgroundFilename!="" or BackgroundFilename is NOT NULL ';?

Big-Gaz
08-08-2009, 03:03 PM
Hi,

Thanks for the reply.
That seems to give all records

What I am after is if BackgroundFilename has a value in the database to give the result if BackgroundFilename is empty in the database don't give this result

DB Looks like:

(5, 'UserA', '5/test99.jpg'),
(60, 'UserB', ''),
(63, 'UserC', ''),
(64, 'UserD', ''),
(92, 'UserE', '92/test.png'),
(90, 'UserF', '');


So as UserA and UserE has a BackgroundFilename I want to display those results.
But if the others users added a BackgroundFilename I would want to display them

OR

Is there away to mark a DB field as Null
This is what I am using the delete the BackgroundFilename


$backgroundfilename = '';
$DB->query( "UPDATE ! SET BackgroundFilename = ? WHERE id=?", array( CUSTOM_TABLE, $backgroundfilename, $userId ) );

Big-Gaz
08-08-2009, 03:35 PM
Think I will do it the easier way and add another field to the DB and when there is a picture put something in it, so it gives me a WHERE to call.

abduraooft
08-08-2009, 03:59 PM
What I am after is if BackgroundFilename has a value in the database to give the result if BackgroundFilename is empty in the database don't give this result
I think an AND should do it, like
$sql = 'SELECT field_name FROM table_name WHERE BackgroundFilename!="" AND BackgroundFilename is NOT NULL ';

Big-Gaz
08-08-2009, 04:49 PM
Hi,

Thanks again for the reply :D
That seem to have done the opposite.

Old Pedant
08-08-2009, 10:31 PM
This code makes NO SENSE to me:


SELECT SQL_CALC_FOUND_ROWS USERNAME_custom FROM WHERE

The table name is supposed to go *AFTER* the word FROM.

Is USERNAME_custom the table name???

If not, and if both SQL_CALC_FOUND_ROWS and USERNAME_custom are *fields*, then where is the comma between them???

Can somebody explain this?

Big-Gaz
08-08-2009, 11:24 PM
Hi,

I got it the wrong way around, when posting the message


$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM USERNAME_custom WHERE BackgroundFilename=""';


I have fixed the problem by using anther DB field