Seapep Posted December 31, 2010 Share Posted December 31, 2010 Hi Folks, I am learning php and mysql so please bear with me and again if this is not in the right place please let me know. Anyways, I have a form setup that will be used to add events for a local sports team. I have 3 tables. Table1(Level) is working fine and populating the drop down form as I need it to. Table 2 is the Events. This is used to track all the event names that are used through the organization. Table 3 is the Schedule. This show all the events that are scheduled. What I need the form to do is allow the client to choose the event type and the level type for the registration process. Can I do this with mutliple dropdown lists with mysql/php? Here is what I have that is working. mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $sql = "SELECT\n" . "levels.LevelID,\n" . "levels.LevelName\n" . "FROM\n" . "levels\n"; $result = mysql_query($sql) or die(mysql_error()); $options=""; while($row = mysql_fetch_array($result)){ $LevelID=$row["LevelID"]; $LevelName=$row["LevelName"]; $options.="<OPTION VALUE=\"$LevelID\">".$LevelName.'</option>'; } ?> <style type="text/css"> <!-- body p { color: #F00; } --> </style> <table width="500" border="1" align="center" cellpadding="0" cellspacing="1" > <tr> <td> <form name="form1" method="post" action="scheduleinsert_ac.php"> <table width="100%" border="1" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><div align="center"> <p><strong>Myers Schedule Form</strong></p> </div></td> </tr> <tr> <td>Event Name</td> <td><div align="center">:</div></td> <td></td> </tr> <tr> <td>Level</td> <td><div align="center">:</div></td> <td><select name="LevelID"> <OPTION VALUE="0">Choose <?php echo $options;?> </select></td> </tr> Link to comment https://forums.phpfreaks.com/topic/223048-form-population/ Share on other sites More sharing options...
BLaZuRE Posted December 31, 2010 Share Posted December 31, 2010 Yes, why wouldn't you? You can put multiple drop-downs in HTML, so what's the problem? Maybe I'm not understanding what you're trying to ask. Link to comment https://forums.phpfreaks.com/topic/223048-form-population/#findComment-1153217 Share on other sites More sharing options...
Seapep Posted December 31, 2010 Author Share Posted December 31, 2010 I guess the issue is where would I put the 2nd query which would populate the 2nd drop down list? I have seen a lot of examples but they all are linking back to each other via a relationship. Whereas what I have is 2 drop down lists querying 2 different tables. I tried to copy what I have with the corresponding fields and all I get is a blank field. Link to comment https://forums.phpfreaks.com/topic/223048-form-population/#findComment-1153218 Share on other sites More sharing options...
fortnox007 Posted December 31, 2010 Share Posted December 31, 2010 just apart frm that i would add another table named category (like weekly monthly children elder etc) that way in the end you can out put everything in nice categories. back to your thing. I think this is what you are looking for: ie. SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.column1 = table2.column1; source: http://articles.techrepublic.com.com/5100-10878_11-1050307.html -also nice for people to make a category first. so you first show them the existing categories, and give thme the opportunity to add one which is ofcourse pretty simple (ID, category_name, category_description) Link to comment https://forums.phpfreaks.com/topic/223048-form-population/#findComment-1153220 Share on other sites More sharing options...
BLaZuRE Posted December 31, 2010 Share Posted December 31, 2010 You can also do something like: $query1 = 'SELECT field1, field2 FROM table1'; while($row=mysql_fetch_array($query1) { //Code to echo form options } $query2 = 'SELECT field1, field2 FROM table2'; while($row=mysql_fetch_array($query2) { //Code to echo form options for events } You don't need to prefix fieldX with tableX (tableX.fieldX) if you're only using one table in the query. Link to comment https://forums.phpfreaks.com/topic/223048-form-population/#findComment-1153222 Share on other sites More sharing options...
Seapep Posted December 31, 2010 Author Share Posted December 31, 2010 So something lilke this <?php require_once 'dblogin.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $sql = "SELECT\n" . "levels.LevelID,\n" . "levels.LevelName\n" . "FROM\n" . "levels\n"; $result = mysql_query($sql) or die(mysql_error()); $options=""; while($row = mysql_fetch_array($result)){ $LevelID=$row["LevelID"]; $LevelName=$row["LevelName"]; $options.="<OPTION VALUE=\"$LevelID\">".$LevelName.'</option>'; $sql2 = "SELECT\n" . "events.EventID,\n" . "events.EventName\n" . "FROM\n" . "events\n"; $result2 = mysql_query($sql2) or die(mysql_error()); $options2=""; while($row2 = mysql_fetch_array($result2)) $EventID=$row2["EventID"]; $EventName=$row2["EventName"]; $options2.="<OPTION VALUE=\"$EventID\">".$EventName.'</option>'; } ?> <table width="500" border="1" align="center" cellpadding="0" cellspacing="1" > <tr> <td> <form name="form1" method="post" action="scheduleinsert_ac.php"> <table width="100%" border="1" cellspacing="1" cellpadding="3"> <tr> <td colspan="3"><div align="center"> <p><strong>Schedule Form</strong></p> </div></td> </tr> <tr> <td>Event Name</td> <td><div align="center">:</div></td> <td><select name="EventID"> <OPTION VALUE="0">Choose <?php echo $options2;?> </select></td> </tr> <tr> <td>Level</td> <td><div align="center">:</div></td> <td><select name="LevelID"> <OPTION VALUE="0">Choose <?php echo $options;?> </select></td> </tr> Link to comment https://forums.phpfreaks.com/topic/223048-form-population/#findComment-1153227 Share on other sites More sharing options...
Seapep Posted December 31, 2010 Author Share Posted December 31, 2010 Thanks for the help guys. I got it to work, in the above code I was missing a set of { } brackets. Cheers, Link to comment https://forums.phpfreaks.com/topic/223048-form-population/#findComment-1153233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.