blasterstudios
Technical User
OK. Here's what i'm trying to do:
I have 2 tables in my database. One is Messages, the other is Followups.
What I'm trying to do is pull all the rows in Messages that have associated rows in the Followups table that the 'read' column is marked "N". I'm running 2 queries for this, and somewhere inside them it's not working.
My first query pulls all the rows from the Followups table that are:
1. Owned by the currently logged in User
2. Show a "N" in the Read field.
3. I believe my problem lies somewhere in the SELECT DISTINCT statement, but i'm not sure how to go about doign this. Here is the query:
$colname_pullunreadfollowups = "1";
if (isset($_SESSION['owneruser'])) {
$colname_pullunreadfollowups = (get_magic_quotes_gpc()) ? $_SESSION['owneruser'] : addslashes($_SESSION['owneruser']);
}
mysql_select_db($database_bsaccounts, $bsaccounts);
$query_pullunreadfollowups = sprintf("SELECT DISTINCT messageid, owneruser, `read` FROM followups WHERE owneruser = '%s' AND `read` = 'N'", $colname_pullunreadfollowups);
$pullunreadfollowups = mysql_query($query_pullunreadfollowups, $bsaccounts) or die(mysql_error());
$row_pullunreadfollowups = mysql_fetch_assoc($pullunreadfollowups);
$totalRows_pullunreadfollowups = mysql_num_rows($pullunreadfollowups);
Then, I'm using this code, i don't know why, i found it somewhere on this forum, and it may be part of the problem:
while ($row_pullunreadfollowups) {
$msgid[] = $row['messageid'];
}
$msgid = array($msgid);
Lastly, my 2nd query pulls the topics from the Messages table that match the messageids found with unread followups:
$colname_pullunreads = "1";
if (isset($_SERVER['msgid'])) {
$colname_pullunreads = (get_magic_quotes_gpc()) ? $_SERVER['msgid'] : addslashes($_SERVER['msgid']);
}
mysql_select_db($database_bsaccounts, $bsaccounts);
$query_pullunreads = sprintf("SELECT messageid, `date`, subject FROM messages WHERE messageid = %s", $colname_pullunreads);
$pullunreads = mysql_query($query_pullunreads, $bsaccounts) or die(mysql_error());
$row_pullunreads = mysql_fetch_assoc($pullunreads);
$totalRows_pullunreads = mysql_num_rows($pullunreads);
In case you didn't figure it out, I'm using Dreamweaver.
At what point is this not working? My result shows up as only 1 message. I know there is 2 in database (there is 1 unread Followup for 2 different Messages).
Thanks for the help.
I have 2 tables in my database. One is Messages, the other is Followups.
What I'm trying to do is pull all the rows in Messages that have associated rows in the Followups table that the 'read' column is marked "N". I'm running 2 queries for this, and somewhere inside them it's not working.
My first query pulls all the rows from the Followups table that are:
1. Owned by the currently logged in User
2. Show a "N" in the Read field.
3. I believe my problem lies somewhere in the SELECT DISTINCT statement, but i'm not sure how to go about doign this. Here is the query:
$colname_pullunreadfollowups = "1";
if (isset($_SESSION['owneruser'])) {
$colname_pullunreadfollowups = (get_magic_quotes_gpc()) ? $_SESSION['owneruser'] : addslashes($_SESSION['owneruser']);
}
mysql_select_db($database_bsaccounts, $bsaccounts);
$query_pullunreadfollowups = sprintf("SELECT DISTINCT messageid, owneruser, `read` FROM followups WHERE owneruser = '%s' AND `read` = 'N'", $colname_pullunreadfollowups);
$pullunreadfollowups = mysql_query($query_pullunreadfollowups, $bsaccounts) or die(mysql_error());
$row_pullunreadfollowups = mysql_fetch_assoc($pullunreadfollowups);
$totalRows_pullunreadfollowups = mysql_num_rows($pullunreadfollowups);
Then, I'm using this code, i don't know why, i found it somewhere on this forum, and it may be part of the problem:
while ($row_pullunreadfollowups) {
$msgid[] = $row['messageid'];
}
$msgid = array($msgid);
Lastly, my 2nd query pulls the topics from the Messages table that match the messageids found with unread followups:
$colname_pullunreads = "1";
if (isset($_SERVER['msgid'])) {
$colname_pullunreads = (get_magic_quotes_gpc()) ? $_SERVER['msgid'] : addslashes($_SERVER['msgid']);
}
mysql_select_db($database_bsaccounts, $bsaccounts);
$query_pullunreads = sprintf("SELECT messageid, `date`, subject FROM messages WHERE messageid = %s", $colname_pullunreads);
$pullunreads = mysql_query($query_pullunreads, $bsaccounts) or die(mysql_error());
$row_pullunreads = mysql_fetch_assoc($pullunreads);
$totalRows_pullunreads = mysql_num_rows($pullunreads);
In case you didn't figure it out, I'm using Dreamweaver.
At what point is this not working? My result shows up as only 1 message. I know there is 2 in database (there is 1 unread Followup for 2 different Messages).
Thanks for the help.