Jump to content

Form population


Seapep

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.