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. Quote Link to comment 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; } } Quote Link to comment 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! Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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']; Quote Link to comment 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.=) Quote Link to comment 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.