Jump to content

Can some please check my code if what is wrong


cruxaders

Recommended Posts

btw i forgot to tell

 

i got 2 tables

 

1st table is

 

users,

with fields

-id

-username

-imagelocation

 

2nd table is

forum_replies

with fields

-id

-uid

-message

 

what i want to do in sql is to get the image location..

$avatar2 = mysql_query("SELECT users.username, forum_replies.message FROM users,forum_replies WHERE users.id= forum_replies.uid ")or die(mysql_error());

 

but when i echo the $avatar2

 

it appears

Resource id #3

 

idk what the problem on my code

but when i echo the $avatar2

 

it appears

Resource id #3

That's actually the correct way your code should be acting.  If you look in the manual at mysql_query you will see the method returns a 'resouce' which is what is being outputted.  You need to use something like mysql_fetch_assoc to extract the actual data.

if thats the correct code why the image not yet shawn..what will i do to make the image visible :(

It's not the correct code, but the code you have is acting appropriately.  Like I said, you need to use something like mysql_fetch_assoc, pass it in the resource, and extract the information.  Click the link to the manual and you will see a variety of examples.

 

This is actually a PHP Coding question, I will move it there.  Post the relevant PHP code.

this the other code with fetch

 

	$avatar2 = mysql_query("SELECT users.username, forum_replies.message FROM users,forum_replies WHERE users.id= forum_replies.uid ")or die(mysql_error());
		$row3 = mysql_fetch_assoc($avatar2);
		$location2 = $row4['imagelocation'];


<table width=\"100\" border=\"0\" align=\"center\">
  <tr>
    <td><img src =\"$location2\" width=\"100\" hieght=\"100\"></td>
  </tr>
</table>

In your query you only SELECT "users.username" & "forum_replies.message", so that's all you can access.  I don't see where you're echoing out $avatar2.  The $location2 looks correct, but I see where the query or code for that is.

$avatar2 = mysql_query("SELECT users.imagelocation FROM users , forum_replies WHERE  users.id=forum_replies.uid ")or die(mysql_error());
	$row4 = mysql_fetch_assoc($avatar);
	$location2 = $row4['imagelocation'];
<table width=\"100\" border=\"0\" align=\"center\">
  <tr>
    <td><img src =\"$location2\" width=\"100\" hieght=\"100\"></td>
  </tr>
</table>

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.