This is driving me crazy! I have messages stored in my MySQL database. Each message is assigned either a store, a group or an employee. I am trying to make the message display if the employee is either assigned to the same store, group, or has the same employee ID as the message is assigned. Here is what I have: function global_messages() { // Used to display any global system messages $today = date('Y-m-d'); // Get today's date $global_messages = mysql_query("SELECT * FROM messages WHERE type ='1' AND '$today' BETWEEN start_date AND end_date"); // Find all global messages assuming global is type 1 where today is between the start & end dates while($msgs = mysql_fetch_array($global_messages)) { // This is the part I'm having trouble with: if (($msgs['rec_store'] == $_SESSION["stores_assigned"]) || ($msgs['rec_group'] == $_SESSION["group_assigned"]) || ($msgs['rec_id'] == $_SESSION["id"])) { echo $msgs['content']; } // End if } // End while } // End function PHP: Could someone tell me what I'm doing wrong? I am POSITIVE the session variables are assigned and correct as I can echo them onto the page.
Are you getting errors? If so, what do they say? Generally, I would work through this line by line. 1--echo your SQL statement to see what the actual query is that is being run. Is it formed correctly? Are the variables you are using the intended ones? 2--run that SQL statement manually in myphpadmin or whatever you have. Is it returning results? Is it giving any errors? 3--inside your while loop, first echo all your $msgs and $_SESSION data then have the if statement run. For the if statment, instead of echoing $msg['content'] echo "success" or something else so you can easily see the rows that succeed. Manually go through each row and see which ones should have succeeded and figure out why they didn't.
Well it is displaying messages, but the wrong ones to the wrong people. If I do ONE "if" without any OR's (||), it works fine, but once I add in any || it starts showing messages that do not equal the IF statement.