Codes here !
2 posts • Page 1 of 1
- php-forum Active User
- Posts: 266
- Joined: Tue Apr 08, 2003 5:18 am
- Location: Ottawa, Canada
- Posts: 2272
- Joined: Sat Jul 05, 2003 1:18 pm
- Location: A bunk in the back
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.
Who is online
Users browsing this forum: No registered users and 1 guest