Problem query'ing mysql database. Please help

Codes here !

Moderators: egami, macek, gesf

Post Reply
liquedus
php-forum Active User
php-forum Active User
Posts: 264
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Wed Jul 09, 2003 10:03 am

well you are on the right track.. it will contain a resource id and now you need a function to extract that information out of that resource... try looking at php.net's mysql functions :wink:

User avatar
swirlee
Moderator
Moderator
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Wed Jul 09, 2003 1:56 pm

Unforgiven wrote:$weapon = mysql_query("SELECT Weapons.Name FROM Weapons, Members WHERE Members.Weapon='Weapons.id' and Members.Username = '$Username';");
That query returns Resource ID #5, when it should be returning a string.


Your analysis that it "should be" returning a string is incorrect. According to the docs, mysql_query() "should be" returning a resource, and that appears to be the case. Now you need to fetch the result of that query by passing the name of the resource to mysql_fetch_array() or mysql_fetch_assoc() like this:

Code: Select all

<?
   $weapon = mysql_query('SELECT Weapons.Name FROM Weapons, Members WHERE Members.Weapon=Weapons.id and Members.Username = \'' . $Username. '\'');
   $weapon_array = mysql_fetch_assoc($weapon);
?>


This will populate $weapon_array with the returned row. Note that if you expect the query to return more than one row, you'll want to place mysql_fetch_assoc() a while() loop or similar. Refer to the docs for help with the usage. Also note that I cleaned up your syntax a bit. I could lecture people on syntax, legibility, optimization, conventions, etc., but for your sake I won't. Enjoy.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest