Jump to content


Photo

Drop down menu


  • Please log in to reply
5 replies to this topic

#1 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 16 October 2006 - 12:55 PM

I have a database and I have a relationship from one DB to another...

now I want to put a drop down menu on my PHP page to select from that relationship...

does anyone has some documentation on this... ???



#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 16 October 2006 - 12:57 PM

Are they different databases or just different tables in a single database?


me!

#3 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 16 October 2006 - 04:56 PM

one data base different tables so i guess the relationship is between tables...

#4 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 16 October 2006 - 05:17 PM

A little database structure would be cool and what fields you want to use.

Ray

#5 gijew

gijew
  • Members
  • PipPipPip
  • Advanced Member
  • 240 posts
  • LocationCalifornia

Posted 16 October 2006 - 05:19 PM

I don't know your table structure but off the top of my head as long as you have a foreign key between the two (unique number that identifies the parent record in the child table) the query could be done several ways but most common would be looping through the two tables like this...
<?php
$parent_query = mysql_query("SELECT id, name FROM parent_table ORDER BY name ASC");
while ($parent= mysql_fetch_array($parent_query)) {
  $child_query = mysql_query("SELECT id, name FROM child_table WHERE foreign_key = $row[id] ORDER BY name ASC");
  while ($child = mysql_fetch_array($child_query)) {
    // display your code
  }
}
?>

I'm considered good looking in some countries

#6 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 17 October 2006 - 05:20 PM

This is what i created .... what i need is that the states fields will show a dropdown menu and chosse from a table i have with all the states ... the table name is "states"

hope this helps

<html>
<head>
<title>Add Record</title>
</head>
<body>

<?php

$user="root";
$pass="12345";

$self=$_SERVER['PHP_SELF'];
$userid=$_POST['userid'];
$name=$_POST['name'];
$last=$_POST['last'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$email=$_POST['email'];
$gender=$_POST['gender'];
$nickname=$_POST['nickname'];
$age=$_POST['age'];

?>

<form action="<?php echo( $self );?>" method="post">
User ID: <input type="text" name="userid" size"30"><br>
Name: <input type="text" name="name" size"30"><br>
Last: <input type="text" name="last" size"30"><br>
City: <input type="text" name="city" size"30"><br>
State: <input type="text" name="state" size"30"><br>
Country: <input type="text" name="country" size"30"><br>
Email: <input type="text" name="email" size"30"><br>
Gender: <input type="text" name="gender" size"30"><br>
Nickname: <input type="text" name="nickname" size"30"><br>
Age: <input type="text" name="age" size"30"><br>
<input type="submit" value="Submit"><br>
</form> 



<?php

    if($userid and $name and $last and $city and $state and $country and $email and $gender and $nickname and $age){
 

    $dbh=mysql_connect("localhost", $user, $pass) or die ("Err:Conn");
 
    if($dbh){
      echo ("Congrats!!!");

    $rs=mysql_select_db("natgal", $dbh) or die ("Err:Db");
   
 
    $sql="INSERT INTO users( userid, name, last, city, state, country, email, gender, nickname, age)
          VALUES ($userid, \"$name\", \"$last\", \"$city\", \"$state\", \"$country\", \"$email\", \"$gender\", \"$nickname\", \"$age\")";
   
    $rs=mysql_query($sql, $dbh);
   
    if($rs){
      echo ("Record Added!!!");
     
          }
      }
    }

?>

</body>
</html>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users