Jump to content

[SOLVED] sql query not working....


Zeradin

Recommended Posts

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

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;
			}
}

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'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.