Jump to content

[SOLVED] Resource ID 4?


pugboy

Recommended Posts

I am creating a shopping cart script for my site, and I am trying to test the store name function...

 

<?php
mysql_connect("localhost", "*****", "******") or die(mysql_error());
mysql_select_db("ffforum_shop") or die(mysql_error());
$sid = $_GET["id"];
$q = "SELECT title FROM user WHERE id = '" . $sid . "'";
$title = mysql_query($q);
?>

 

$title becmes "Resource ID #4"... Why is that? Shouldn't it output my shop title?

 

(Sorry, I am a MySQL n00b XD)

Link to comment
https://forums.phpfreaks.com/topic/113824-solved-resource-id-4/
Share on other sites

mysql_query returns a result set.

<?php
mysql_connect("localhost", "*****", "******") or die(mysql_error());
mysql_select_db("ffforum_shop") or die(mysql_error());
$sid = $_GET["id"];
$q = "SELECT title FROM user WHERE id = '" . $sid . "'";
$title = mysql_query($q);
while ($row = mysql_fetch_assoc($title))
   echo $row['title'];
?>

Link to comment
https://forums.phpfreaks.com/topic/113824-solved-resource-id-4/#findComment-584912
Share on other sites

@lemmin: Well, he's only going to have one row because he's using an ID to pull the right row.  Try:

 

<?php

mysql_connect("localhost", "*****", "******") or die(mysql_error());

mysql_select_db("ffforum_shop") or die(mysql_error());

$sid = $_GET["id"];

$q = "SELECT title FROM user WHERE id = '" . $sid . "'";

$result = mysql_query($q);

list($title) = mysql_fetch_assoc($result);

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/113824-solved-resource-id-4/#findComment-584915
Share on other sites

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.