freshrod Posted May 4, 2006 Share Posted May 4, 2006 I posted about this before and got an answer, but while it did stop the error, it still isn't working how I wanted. Basically I have a value in a DB field that I want to check. The column is set up like this:'alumInfo enum ('0','1') NOT NULL default='0',I query it like this:$sql = mysql_query("SELECT alumInfo FROM users WHERE username='$username' AND password='$password'");Then I want to check what the value is. If it's 0 I want to print one thing, if it's 1 I want to print something else. I've tried something like this:$row = mysql_fetch_array($sql); // I'm thinking the problem lies here...if($row['alumInfo'] == '0') { echo "one thing";} else {echo "something else";}It seems to ignore the first 'echo' and only prints the last one, even though the default value is '0'.Any suggestions? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/ Share on other sites More sharing options...
trq Posted May 4, 2006 Share Posted May 4, 2006 You never query the database.[code]if ($result = mysql_query($sql)) { $row = mysql_fetch_array($result); if (!$row['alumInfo']) { echo "one thing"; } else { echo "something else"; }}[/code]Notice also this line... if (!$row['alumInfo']) {. 0 is false in php, so you dont need to do it the way you did. Besides, integers should not be quted as you had. Quote Link to comment https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/#findComment-33309 Share on other sites More sharing options...
freshrod Posted May 4, 2006 Author Share Posted May 4, 2006 Thanx for the help thorpe, but it still isn't showing the echo?I pasted the code in that you put. I really don't understand what the problem is. Quote Link to comment https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/#findComment-33332 Share on other sites More sharing options...
ober Posted May 4, 2006 Share Posted May 4, 2006 Actually thorpe, it would appear like he's using strings instead of integers. So the way he had it origionally should work, and he does query the database... it's above the output.However, if you truly intend to use integers (0,1), you should change the table and the if statement if it is currently treating those as strings.Are you sure any of the fields actually have 0 in them?? Quote Link to comment https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/#findComment-33338 Share on other sites More sharing options...
freshrod Posted May 4, 2006 Author Share Posted May 4, 2006 Thanx Ober. When I run (SELECT * FROM users;) it shows a 0 in the field. I really don't know what the deal is. I've used similar querys and such before... never had this much trouble. Quote Link to comment https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/#findComment-33350 Share on other sites More sharing options...
freshrod Posted May 5, 2006 Author Share Posted May 5, 2006 Maybe I'm asking the wrong question. Is there a better way to run a query, check the data, and run an if/else of it?Maybe my problem lies in my approach? Or the way I'm writing the query? Quote Link to comment https://forums.phpfreaks.com/topic/9056-am-i-getting-the-data-from-the-query/#findComment-33483 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.