Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT returns Resource ID

Status
Not open for further replies.

Lightfoot

Programmer
Dec 31, 2001
1
CA
if($selectteam) {
$db = mysql_connect("localhost", "root");
mysql_select_db("teams",$db);
$title = mysql_query("SELECT name FROM teams WHERE id='$selectteam'",$db);
$tag = mysql_query("SELECT tag FROM teams WHERE id='$selectteam'",$db);
echo $tag;

This is the code I am using, I have looked it over a thousand times, and have had other programmers check it out too. The problem here is it returns $title as "Resource id #2" while returning $tag as "Resource id#3". Shouldn't this return the actual values of the cells, not the id numbers for them?

This has been bugging me for a long time, if anyone can, please help!
 
mysql_query only returns a resource identifier or FALSE if the query was not executed correctly.

Once you have that resource id, then you can run a fetch statment on that ID (mysql_fetch_array(), mysql_fetch_field(), mysql_fetch_assoc(), etc).

replace echo $tag; with

while ($row = mysql_fetch_array($tag)) {
echo $row["name"];
}
 
or even

$row = mysql_fetch_array($tag);
echo $row["name"];

if you only expect a single result from the sql query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top