Zeradin Posted August 15, 2008 Share Posted August 15, 2008 I have an id=1 being returned to this. I know that isn't the problem because i echo'd the id before the query: else { // create query $query = 'SELECT type FROM reviews WHERE id = '.$id.''; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); switch ($result) { case show: include('reviews/show.php'); break; case album: include('reviews/album.php'); break; case venue: include('reviews/venue.php'); break; } } now when i echo out $result I get "Resource id #5" that's not right. i am looking at my reviews table and there is an id one and the type is show, but it's not getting that value. please help, i'm almost done with this thing. Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/ Share on other sites More sharing options...
pocobueno1388 Posted August 15, 2008 Share Posted August 15, 2008 Try <?php else { // create query $query = 'SELECT type FROM reviews WHERE id = '.$id.''; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $row = mysql_fetch_assoc($result); switch ($row['type']) { case show: include('reviews/show.php'); break; case album: include('reviews/album.php'); break; case venue: include('reviews/venue.php'); break; } } Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/#findComment-617535 Share on other sites More sharing options...
Zeradin Posted August 15, 2008 Author Share Posted August 15, 2008 amazing thank you! just curious so i actually learn what's going on here why wasn't what i was doing working? THANKS! Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/#findComment-617539 Share on other sites More sharing options...
pocobueno1388 Posted August 15, 2008 Share Posted August 15, 2008 You were trying to use the $result variable, which is just the query handle. You need to extract the fields from the database by doing $row = mysql_fetch_assoc($result); Does that make sense? Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/#findComment-617545 Share on other sites More sharing options...
Zeradin Posted August 15, 2008 Author Share Posted August 15, 2008 yes makes perfect sense. but i tried $type=$result['type'] and then switched on $type and i also tried selecting all and then setting $type why didn't those work? Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/#findComment-617548 Share on other sites More sharing options...
pocobueno1388 Posted August 15, 2008 Share Posted August 15, 2008 yes makes perfect sense. but i tried $type=$result['type'] and then switched on $type and i also tried selecting all and then setting $type why didn't those work? You don't use $result['type']...you have to use $row['type']. So do $type = $row['type']; Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/#findComment-617556 Share on other sites More sharing options...
Zeradin Posted August 15, 2008 Author Share Posted August 15, 2008 gotcha. Thanks for all the help. I'm getting this stuff... slowly... but i am getting it.=) Link to comment https://forums.phpfreaks.com/topic/119873-solved-sql-query-not-working/#findComment-617559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.