Jump to content

[SOLVED] Problem with a Query :S


slawrence10

Recommended Posts

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);

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.