pugboy Posted July 8, 2008 Share Posted July 8, 2008 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 More sharing options...
lemmin Posted July 8, 2008 Share Posted July 8, 2008 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 More sharing options...
DarkWater Posted July 8, 2008 Share Posted July 8, 2008 @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 More sharing options...
pugboy Posted July 8, 2008 Author Share Posted July 8, 2008 What should I echo? $title = nothing $title[0] = nothing list($title) = error Link to comment https://forums.phpfreaks.com/topic/113824-solved-resource-id-4/#findComment-584918 Share on other sites More sharing options...
pugboy Posted July 8, 2008 Author Share Posted July 8, 2008 I guess it should have been mysql_fetch_array... Now it works Thanks Link to comment https://forums.phpfreaks.com/topic/113824-solved-resource-id-4/#findComment-584925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.