Ok, before I begin my question, let me present the code.
PHP Code:
...
$query = mysql_query("SELECT posttitle, userid, post FROM post WHERE postid = $postid");
$result = mysql_fetch_array($query);
$usrquery = mysql_query("SELECT username FROM user WHERE userid = \"result[userid]\"");
$usr = mysql_fetch_array($usrquery);
echo $result['posttitle'] . "<br />";
echo $usr['userid'] . "<br />";
print $usrquery . "<br />"; // Debug Statement
print $query . "<br />"; // Debug Statement
echo $result['post'] . "<br />";
...
For example purposes, lets say this is how my SQL table looks:
PHP Code:
--------------------------- ---------------------------
| post | | user |
--------------------------- ---------------------------
| posttitle | userid | post | | userid | username |
--------------------------- ---------------------------
| test1 | 1 | test1 | | 1 | joshuad |
--------------------------- ---------------------------
So the object of this is to use a one to one relationship with userid, and I've tried several approaches to make this work. I've tried using an INNER JOIN statement, which did the same thing for me that this method has.
This is the output:
Test1
Resource id #8
Resource id #7
Test1
As you can see, $query is bringing back the proper results, but $usrquery is not. Now for debugging purposes I told the script to print out what exactly the two variables contain, and instead of it printing the expected SELECT statements, I receive these Resource id's. I've dealt with this before on a script that I had written in the past, but I don't recall what I did to fix it.
Obviously the objective here is for echo $usr['userid'] . "<br />"; to print out the username (instead of the obvious NULL statement that it is passing off). Any help would be appreciated.
Ok, so obviously the SQL tables didn't format quite the way I wanted them to...but you get the point.
Bookmarks