Jump to content

Processing a database


Drezard

Recommended Posts

Hello, I have 3 variables in my database... Now, the variables (lets call em 1, 2 and 3) arn't always there... Meaning...

 

my database is like this:

 

1      |  2    |  3  |

daniel    T

peter              F

john      T        F

 

Now, I want to output these things from the database but whenever it gets to one without a variable (say 3 is missing) the query fails. (The query:

$query = "SELECT 1, 2, 3 FROM table";

)

 

So... my question is how do i output these three things even if one is missing (example how would i output Daniel, Peter and Johns record even if they had parts missing?)

 

- Cheers, Daniel

 

 

Link to comment
https://forums.phpfreaks.com/topic/44105-processing-a-database/
Share on other sites

Just check your query if it is blank and put a default value for the coloum:

the database wil then be:

1       |   2    |  3   |
daniel     T        0
peter      0        F
john       T        F

 

THe code:

If (!$query){
echo "None data.";}
elseif ($query){
echo $query; }

 

Is that what you wanted?

Link to comment
https://forums.phpfreaks.com/topic/44105-processing-a-database/#findComment-214150
Share on other sites

ok.. Well simple.

Just set the default values for the coloums to 0

As 0 is null therefor nothing.

So do you query:

$query = mysql_query("SELECT * FROM table WHERE `name`=$'name'");

 

the verify it:

If (!$query){
echo "None data.";}
elseif ($query){
echo $query; }

Link to comment
https://forums.phpfreaks.com/topic/44105-processing-a-database/#findComment-214212
Share on other sites

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.