Trouble fetching joined field
Posted: Sat Sep 20, 2008 9:40 pm
I use the following query at a web app
$res=mysql_query("SELECT posts.postID , posts.title, members.username, posts.postdate, posts.userID FROM members INNER JOIN posts ON members.id = posts.userID WHERE posts.userID =".$_GET['userpost']);
This query runs fine when i run it at phpmyadmin but, when i run it from my page i can't fetch the members.username field.
I use this code to show the rows
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
Print "<tr>";
Print "<td><a href='readpost.php?postID=".$row[postID]."' class='style1'>".$row[title]."</a></td>";
Print "<td>".$row[username]."</td>";
Print "<td>".$row[postdate]."</td>";
//Print "<td>".$row[catname]."</td>";
Print "</tr>";
}
I also tried to change the query to "SELECT posts.postID AS Pid, posts.title AS Pttl, members.username AS USRname ...., and to access the fields by using int ($row[0]...)
but none of them worked.
So, can someone tell me what i do wrong ?
$res=mysql_query("SELECT posts.postID , posts.title, members.username, posts.postdate, posts.userID FROM members INNER JOIN posts ON members.id = posts.userID WHERE posts.userID =".$_GET['userpost']);
This query runs fine when i run it at phpmyadmin but, when i run it from my page i can't fetch the members.username field.
I use this code to show the rows
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
Print "<tr>";
Print "<td><a href='readpost.php?postID=".$row[postID]."' class='style1'>".$row[title]."</a></td>";
Print "<td>".$row[username]."</td>";
Print "<td>".$row[postdate]."</td>";
//Print "<td>".$row[catname]."</td>";
Print "</tr>";
}
I also tried to change the query to "SELECT posts.postID AS Pid, posts.title AS Pttl, members.username AS USRname ...., and to access the fields by using int ($row[0]...)
but none of them worked.
So, can someone tell me what i do wrong ?