Webmaster Forum

Go Back   Webmaster Forum > Web Development > Web Design Lobby

Web Design Lobby Forum for general web design issues not specific to scripting or graphics.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 02-04-2009, 10:25 AM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Is sql, when making a query, is there such thing as where = (isset('id')) ?

When making a query, i'm trying to grab the rows from a table only if the column "type" is isset or not empty.

So is there something in sql that will do what isset() and empty() does in php?
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 02-04-2009, 12:55 PM
ScriptMan's Avatar
ScriptMan ScriptMan is offline
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 14,038
iTrader: 4 / 100%
Here's a quick code snippett from something I just wrote modified to what you want.

Quote:
$sql = "select * from tablename where cap_id=$scap_id ";
$result=mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{ $answer=$row[answer]; // gets the DB answer
}
// then if empty we abort
if ($answer==' ') { echo "<b>The field was empty"; exit; }

}
If the string is emtpy ' ' then the conditional happens.
You can do anything you like in the final { conditional }. I just did a quick rewrite for you to have a sample.
 
Reply With Quote
  #3  
Old 02-04-2009, 07:48 PM
Hades's Avatar
Hades Hades is offline
Senior Web Developer
 
Join Date: 01-23-07
Location: Argentina
Posts: 2,273
iTrader: 0 / 0%
depends on what that "empty" means to you.

If the column is nullable, you can set a WHERE statement:
Code:
WHERE `type` IS NOT NULL
if empty to you means an empty string:
Code:
WHERE `type` <> ''
or something that covers both cases:
Code:
WHERE `type` IS NOT NULL AND `type` <> ''
 
Reply With Quote
  #4  
Old 02-04-2009, 08:08 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
empty means just there is nothing in the column for that row.

the column 'type' has 8 i different possible values. strong, weak, black, ...
However, some rows are not accurate and do not have a value in the 'type'.

What i'm trying to do is to grab data from every row with the exception of the rows w/o a type value.

Currently, in phpmyadmin, i have configured the column 'type' to be varchar with 20 length. Do you think i should and how could i make these values 'nullable'?

WHERE 'type' IS NOT NULL
is exactly what i'm looking for. Thx for your answer.
 
Reply With Quote
  #5  
Old 02-04-2009, 08:17 PM
Hades's Avatar
Hades Hades is offline
Senior Web Developer
 
Join Date: 01-23-07
Location: Argentina
Posts: 2,273
iTrader: 0 / 0%
to make a value nullable you can edit the field from phpMyAdmin and there is an option to set it to be whether "NULL" or "NOT NULL".

1-NULL means that this value can be really empty. You can build and INSERT INTO statement and not specify any value for that field, in that case the value will be NULL. your WHERE statement will say WHERE `type` IS NOT NULL

2-NOT NULL means that you'll always be forced to enter a value for that field (otherwise you will get a mysql error). And if you don't want to put a value, you will have to specify an empty string. an INSERT STATEMENT will have to contain the value: '', and your WHERE statement will be: WHERE `type` <> ''
 
Reply With Quote
  #6  
Old 02-04-2009, 08:34 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Quote:
Originally Posted by Hades View Post
to make a value nullable you can edit the field from phpMyAdmin and there is an option to set it to be whether "NULL" or "NOT NULL".

1-NULL means that this value can be really empty. You can build and INSERT INTO statement and not specify any value for that field, in that case the value will be NULL. your WHERE statement will say WHERE `type` IS NOT NULL

2-NOT NULL means that you'll always be forced to enter a value for that field (otherwise you will get a mysql error). And if you don't want to put a value, you will have to specify an empty string. an INSERT STATEMENT will have to contain the value: '', and your WHERE statement will be: WHERE `type` <> ''
What is the "and" operator for sql?

I'm trying to do the following:

WHERE id=89 "and" type IS NOT NULL;

Thx again
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP quick help!! How to write if (cookie(isset)) 2939195631902 Coding Forum 3 09-23-2009 01:47 PM
Sql Query itHighway Web Design Lobby 1 03-17-2008 12:09 PM
SQL Query Sketch Coding Forum 2 10-13-2004 03:48 PM
PHP Forms - !isset - isset fairyjo Coding Forum 25 11-27-2003 04:09 AM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 07:29 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC