slawrence10 Posted June 10, 2008 Share Posted June 10, 2008 Hey, I've currently got a problem with one of my queries not working and am really puzzled as to why , I think it has something to do with my querying the same table lsucu_users twice (once for query one and three) and so causing the last query to fail but can't pinpoint the problem. The reason for thinking this is because the query 3 returns no record unless the user_id is the same for both the person accessing the page and the written article. I'll give you a quick lowdown of what they do... Query One - Works Fine - Uses the Session Username to get information on the User from the corresponding record in the USERS table Query Two - Works Fine - This takes the ID from the URL and matches it with the corresponding id record entry in the ARTICLES table to get info on the article Query Three - Not Working - This table now takes the author (user id) from the record retrieved in query two, and queries the USER table again to find more information on the user who created the article -------- Thanks for your time, Scott. // QUERY ONE $colname_user = "-1"; if (isset($_SESSION['MM_Username'])) { $colname_user = $_SESSION['MM_Username']; } mysql_select_db($database_lsucu, $lsucu); $query_user = sprintf("SELECT * FROM lsucu_users WHERE username = %s", GetSQLValueString($colname_user, "text")); $user = mysql_query($query_user, $lsucu) or die(mysql_error()); $row_user = mysql_fetch_assoc($user); $totalRows_user = mysql_num_rows($user); //QUERY TWO $colname_editinfo = "-1"; if (isset($_GET['id'])) { $colname_editinfo = $_GET['id']; } mysql_select_db($database_lsucu, $lsucu); $query_editinfo = sprintf("SELECT * FROM lsucu_articles WHERE id = %s", GetSQLValueString($colname_editinfo, "int")); $editinfo = mysql_query($query_editinfo, $lsucu) or die(mysql_error()); $row_editinfo = mysql_fetch_assoc($editinfo); $totalRows_editinfo = mysql_num_rows($editinfo); // QUERY THREE $colname_author = "-1"; if (isset($row_editinfo['author'])) { $colname_author = $row_editinfo['author']; } mysql_select_db($database_lsucu, $lsucu); $query_author = sprintf("SELECT * FROM lsucu_users WHERE id = %s", GetSQLValueString($colname_author, "int")); $author = mysql_query($query_author, $lsucu) or die(mysql_error()); $row_author = mysql_fetch_assoc($author); $totalRows_author = mysql_num_rows($author); Quote Link to comment Share on other sites More sharing options...
luca200 Posted June 10, 2008 Share Posted June 10, 2008 I think you should check the content of 'author' column in articles table, and if its values are valid users id..... Quote Link to comment Share on other sites More sharing options...
slawrence10 Posted June 10, 2008 Author Share Posted June 10, 2008 It takes people to state the obvious before I chech the obvious it seems. Thank you! that solved my problem, though i thought my second author had ID 2 in fact the second record had ID 3. Thank you for your input in solving my problem! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.