Obadiah Posted November 7, 2010 Share Posted November 7, 2010 I am using PHP Version 5.3.1 and MYSQL 5.1.41 and I have my select statement here however i was not sure with the php that im using to filter the results if I should have or could have posted it here or in the PHP section, as part of my question pertains to it as well...if i am posting in the wrong place please let me know and i will move it. ok this is killin me its not working and when it works it works backwards...whats happening is when I use $DArea anywhere in the Query it doesnt work, If I choose a different Area than one in the database It executes the Else Statement(not supposed to do that) and it post data from the same Month, Year and Area to the database...once again what im trying to do is not allow any information from an Area "$DArea" in the database unless the Month or the Year is different. In other words If I fill out information from area "Gym" on November("DMonth") of 2010("DYear") the next time i will be allowed to enter data on it is next month. And if you were wondering Dmonth and DYear are variables tied to the time() function abd it does pass the correct month and time to the database. $DArea = $areaReported; $query = mysql_query("SELECT * FROM $table_name WHERE Month ='$DMonth' AND Year= '$DYear' AND Area = '$DArea'") or die(mysql_error()); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbMonth = $row['Month']; $dbYear = $row['Year']; $dbArea = $row['Area']; } if ($DMonth==$dbMonth&&$DYear==$dbYear&&$DArea==$dbArea) { mysql_query("INSERT INTO $table_name (user_id, Date, Month, Year, Area, percent1, stat1) values ('{$user_id}', '{$realdate}', '{$DMonth}', '{$DYear}', '{$DArea}', '{$percent1}', '{$stat1}')"); // defining the output include("output.inc"); if ($total == "1"){ $output = $output1; } else if ($total == "2"){ $output = $output2; } else if ($total == "3"){ $output = $output3; } else if ($total == "4"){ $output = $output4; } else if ($total == "5"){ $output = $output5; } else if ($total == "6"){ $output = $output6; } else if ($total == "7"){ $output = $output7; } else if ($total == "8"){ $output = $output8; } else if ($total == "9"){ $output = $output9; } else if ($total == "10"){ $output = $output10; } } else echo "<p style=\"color:red;\">A Report for this $areaReported has already been submitted for this Month</p>"; } I have also tried the statement this way. ("SELECT 'Month', 'Year', 'Area' FROM 'data' WHERE 'Month' ='$DMonth' AND 'Year'='$DYear' AND 'Area' = '$DArea'") If it stops any info from hitting the database it stops it all and when the error message I want to appear when someone tries to enter a duplicate record from a specific area for the same month, it does not show unless its a month that does not exist in the database and to get that to even show up I have to take the Area Clause out of the Select statement. I am out of ideas on this one. Can anyone tell me if im even going in the right direction here? Please help Quote Link to comment https://forums.phpfreaks.com/topic/218001-help-with-phpmysql-multi-where-select/ Share on other sites More sharing options...
fenway Posted November 12, 2010 Share Posted November 12, 2010 Sorry, I don't follow. Quote Link to comment https://forums.phpfreaks.com/topic/218001-help-with-phpmysql-multi-where-select/#findComment-1133565 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.