hosker Posted September 23, 2011 Share Posted September 23, 2011 I have a form that I created that pulls data from a table in MySQL database. On submit that data is put into another table. Each time a particular user goes back to that form, I do not want the data that they have already submitted to be an option in the list. Is there a way to do that? Any and all help would be much appreciated. My for code: <form action="submit.php" method="post"> <ul> <li>Username: <?php /*Displays Logged in Users Name*/ echo $_SESSION["usr"];?></li> <li>Weekly Pick <?php $query="SELECT name,id FROM PRO"; $result=mysql_query($query); echo "<select name=PRO value='golfer'>Golfers Name</option>"; while($golfer=mysql_fetch_array($result)){ echo "<option value='$golfer[name]'>$golfer[name]</option>"; } echo "</select>";?></li> <li>Tournament: <?php $query2="SELECT tournament,id FROM 2011_Tournament"; $result2=mysql_query($query2); echo "<select name=2011_Tournament value='tournament'>Tournament</option>"; while($tournament=mysql_fetch_array($result2)){ echo "<option value='$tournament[tournament]'>$tournament[tournament]</option>"; } echo "</select>";?></li> <li>Backup: <?php $query3="SELECT name,id FROM PRO"; /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result3 = mysql_query ($query3); echo "<select name=PRO2 value='backup'>Golfers Name</option>"; // printing the list box select command while($backup=mysql_fetch_array($result3)){//Array or records stored in $nt echo "<option value='$backup[name]'>$backup[name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?></li> <li>Date & Time: <?php date_default_timezone_set('US/Eastern'); $time = date("m-d-Y H:i:s"); echo $time;?></li> </ul> </form> Quote Link to comment Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 If I understand you correctly, when you go back to the form, add a condition to the query that checks that the info is not in the other table. Ex: SELECT * FROM Table1 WHERE Field NOT IN (SELECT * FROM Table2) Hope I understood you correctly. Quote Link to comment Share on other sites More sharing options...
hosker Posted September 23, 2011 Author Share Posted September 23, 2011 That worked fantastically. How do I also have it check for the session user as well? Quote Link to comment Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 How do I also have it check for the session user as well? Not sure what you mean. Check if a session variable exists? That would be if (isset($_SESSION['yourvariable'])) { do something } Quote Link to comment Share on other sites More sharing options...
hosker Posted September 23, 2011 Author Share Posted September 23, 2011 When the form is loaded I it check for the "logged in user" and automatically populate the Username field in the form. How do I check the other table for the specified username that is currently logged into the system as well as previous form entries of the golfer? Quote Link to comment Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 When the form is loaded I it check for the "logged in user" and automatically populate the Username field in the form. How do I check the other table for the specified username that is currently logged into the system as well as previous form entries of the golfer? Ok, I think I get you. You want to make sure it's not in the other table AND that the user is a valid/registered user or whatever. Take that original sql statement and add an AND condition that checks for the user: SELECT * FROM Table1 WHERE Field NOT IN (SELECT * FROM Table2) AND Username IN (SELECT Username FROM Table3) I think that's what you mean. If I'm misunderstanding, I appologize. Quote Link to comment Share on other sites More sharing options...
hosker Posted September 23, 2011 Author Share Posted September 23, 2011 It would be from the same table. Basically I want to check the the "logged in user" has not selected "Said golfer" previously. Quote Link to comment Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 It would be from the same table. Basically I want to check the the "logged in user" has not selected "Said golfer" previously. Change it to NOT IN then. It might help to show your most recent code if that doesn't work. Quote Link to comment Share on other sites More sharing options...
hosker Posted September 23, 2011 Author Share Posted September 23, 2011 Still not working, here is my latest code: <li>Username: <?php /*Displays Logged in Users Name*/ $_SESSION["usr"] = usr; echo usr;?></li> SELECT * FROM Table1 WHERE Field NOT IN (SELECT * FROM Table2) <li>Test Drop Down: <?php $query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND usr NOT IN (SELECT usr FROM weekly_picks)"; $result=mysql_query($query); echo "<select name=PRO value='golfer'>Golfers Name</option>"; while($golfer=mysql_fetch_array($result)){ echo "<option value='$golfer[name]'>$golfer[name]</option>"; } echo "</select>";?></li> Quote Link to comment Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 What does it do/not do? Any errors? Not sure what you're trying to do here, but this invalidly sets a variable (so its not getting set) and then you echo it incorrectly too <li>Username: <?php /*Displays Logged in Users Name*/ $_SESSION["usr"] = usr; echo usr;?></li> I think you mean this? $usr = $_SESSION['usr']; echo $usr; Quote Link to comment Share on other sites More sharing options...
hosker Posted September 23, 2011 Author Share Posted September 23, 2011 I fixed that code, but I still cannot get the following code to work: <li>Username: <?php /*Displays Logged in Users Name*/ echo $userid;?></li> <li>Test Drop Down: <?php $query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND $userid NOT IN (SELECT usr FROM weekly_picks)"; The following code gives me a blank drop down list. Quote Link to comment Share on other sites More sharing options...
TOA Posted September 23, 2011 Share Posted September 23, 2011 I think it's the $userid variable in the sql. That should be a field name, not the value. Try id, assuming usr holds an id in the table. <li>Username: <?php /*Displays Logged in Users Name*/ echo $userid;?></li> <li>Test Drop Down: <?php $query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND id NOT IN (SELECT usr FROM weekly_picks)"; Quote Link to comment Share on other sites More sharing options...
hosker Posted September 24, 2011 Author Share Posted September 24, 2011 I am not storing the userid in the field. Any other suggestions? 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.