jandrews3 Posted October 6, 2008 Share Posted October 6, 2008 Why would the following code give the following output?!? That's just weird! Code: <?php $query_g = "SELECT name, title, member_no, email FROM ithf_groups WHERE title = '$title'"; $result_g= mysql_query($query_g) or die ("Could not perform query: ".mysql_error()); while ($row_g = mysql_fetch_array($result_g)){ print $query_g['id']."-".$query_g['name']."-".$query_g['member_no']."-".$query_g['email']."<br>"; } php?> OUTPUT: S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S S-S-S-S DATABASE TABLE CONTAINS VALID DATA FOR EACH OF THESE FIELDS: Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/ Share on other sites More sharing options...
BillyBoB Posted October 6, 2008 Share Posted October 6, 2008 You are only selecting name, title, member_no, and email from your database in your query. You are trying to use id, name, member_no, and email. You are missing your id in the select. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658580 Share on other sites More sharing options...
Zane Posted October 7, 2008 Share Posted October 7, 2008 aren't you wanting to use $row_g instead of $query_g anyways Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658584 Share on other sites More sharing options...
BillyBoB Posted October 7, 2008 Share Posted October 7, 2008 Wow can't believe I didn't catch that also..... now even I feel stupid. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658585 Share on other sites More sharing options...
jandrews3 Posted October 7, 2008 Author Share Posted October 7, 2008 It was doing the same when the query was "SELECT * FROM ithf_groups WHERE title = '$title'"; But I changed it back again to verify. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658587 Share on other sites More sharing options...
jandrews3 Posted October 7, 2008 Author Share Posted October 7, 2008 I'm use to it. Idiocy is a way of life for me. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658590 Share on other sites More sharing options...
Vermillion Posted October 7, 2008 Share Posted October 7, 2008 Also one little thing on your while loop: while ($row_g = mysql_fetch_array($result_g)){ //... } You should add two = signs next to $row_g, because there are checking if something is true. Using only one = is to asign variables. Sometimes that causes some small bugs in your scripts that can be a royal pain to debug, so you should try to use one = you ASSIGN variables, and two = when you COMPARE them. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658591 Share on other sites More sharing options...
BillyBoB Posted October 7, 2008 Share Posted October 7, 2008 Also one little thing on your while loop: while ($row_g = mysql_fetch_array($result_g)){ //... } You should add two = signs next to $row_g, because there are checking if something is true. Using only one = is to asign variables. Sometimes that causes some small bugs in your scripts that can be a royal pain to debug, so you should try to use one = you ASSIGN variables, and two = when you COMPARE them. He isn't trying to compare them. He is trying to set them while looping through the database tables. OP you should try this: <?php $query_g = "SELECT id, name, title, member_no, email FROM ithf_groups WHERE title = '$title'"; $result_g= mysql_query($query_g) or die ("Could not perform query: ".mysql_error()); while ($row_g = mysql_fetch_array($result_g)){ print $row_g['id']."-".$row_g['name']."-".$row_g['member_no']."-".$row_g['email']."<br>"; } php?> Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658593 Share on other sites More sharing options...
jandrews3 Posted October 7, 2008 Author Share Posted October 7, 2008 Really?! Dag-nabit! All of my WHILE statements in every script I've written uses a single =. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658594 Share on other sites More sharing options...
jandrews3 Posted October 7, 2008 Author Share Posted October 7, 2008 OK. Cool. I don't have to change 500 different scripts. Whew! Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658595 Share on other sites More sharing options...
BillyBoB Posted October 7, 2008 Share Posted October 7, 2008 If you are still looking for your answer please try zanus' suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658601 Share on other sites More sharing options...
jandrews3 Posted October 7, 2008 Author Share Posted October 7, 2008 I did. Thanks. Boy, I haven't made that kind of mistake in quite a while. Oh well. I was past due for something REALLY STUPID. Quote Link to comment https://forums.phpfreaks.com/topic/127320-thats-just-weird/#findComment-658604 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.