Drezard Posted March 24, 2007 Share Posted March 24, 2007 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 More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 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 More sharing options...
Drezard Posted March 24, 2007 Author Share Posted March 24, 2007 How does that work? - cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/44105-processing-a-database/#findComment-214153 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.