kgo Posted March 13, 2010 Share Posted March 13, 2010 Hi guys, having an issue with this query. $userid = mysqli_query($link, "SELECT id FROM members WHERE username = '$username'"); if (!$userid) { $error = 'error error error'; include 'error.php'; exit(); } else $result = mysqli_query($link, "SELECT game_name FROM usergames INNER JOIN games ON game_id = usergames.gameid WHERE usergames.userid = '$userid'"); etcetc... getting this error: 'Catchable fatal error: Object of class mysqli_result could not be converted to string' any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/ Share on other sites More sharing options...
trq Posted March 13, 2010 Share Posted March 13, 2010 What are you doing with the $result variable? Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025468 Share on other sites More sharing options...
kgo Posted March 13, 2010 Author Share Posted March 13, 2010 while ($row = mysqli_fetch_array($result)) { $usergames[] = array('game_name' => $row['game_name']); } that Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025474 Share on other sites More sharing options...
kgo Posted March 13, 2010 Author Share Posted March 13, 2010 followed by this <?php foreach ($usergames as $usergame): ?> <?php htmlspecialchars($usergame['game_name']); ?> <?php endforeach; ?> uh that should be echoing the middle part, fixed that too heh. still having main issue. Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025476 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2010 Share Posted March 13, 2010 You are putting $userid, the result resource from the first query, into the second query statement. You would need to fetch data from the result set of the first query before you could put an actual value into the second query. Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025478 Share on other sites More sharing options...
kgo Posted March 13, 2010 Author Share Posted March 13, 2010 You are putting $userid, the result resource from the first query, into the second query statement. You would need to fetch data from the result set of the first query before you could put an actual value into the second query. oh of course, now I feel stupid heh. I'm quite a newb, which function should I use if I'm retrieving a user id.. mysqli_fetch_something? Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025487 Share on other sites More sharing options...
kgo Posted March 13, 2010 Author Share Posted March 13, 2010 I changed it to this: $userid = mysqli_query($link, "SELECT id FROM members WHERE username = '$username'"); $userid = mysqli_fetch_row($userid); if (!$userid) { $error = 'I suck'; include 'error.php'; exit(); } else $result = mysqli_query($link, "SELECT game_name FROM games INNER JOIN usergames ON game_id = usergames.gameid WHERE usergames.userid = '$userid'"); if (!$result) { $error = 'Error fetching info from database!'; include 'error.php'; exit(); } while ($row = mysqli_fetch_array($result)) { $usergames[] = array('game_name' => $row['game_name']); } but no data is displayed. however if I replace $userid (in the $result query) with an actuall user id, say '3' then the query works and my data is shown. at a loss. Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025493 Share on other sites More sharing options...
kgo Posted March 13, 2010 Author Share Posted March 13, 2010 edit: nevermind it's not working, had a '3' in place of $userid. still doesn't work with $userid in the query.. no data shows up. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/195074-problem-with-mysqli-query/#findComment-1025497 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.