Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Your site was well structured and I found what I was looking for in about 2 minutes. I am looking forward to participating with you in the future..."

Geography

Where in the world do Tek-Tips members come from?

how to pull data from mysql using php

rhodesiascout (Programmer)
27 Oct 00 10:38

Hi guys this is my problem. I   am making a database using mysql where i have 2 tables, one for car manufacturers and one for car models.I've already done that.
I have made a php page where i have 2 drop down  menus.

The first menu shows car makers(manufacturers) and the 2nd nothing.  Now when a user opens the 1st menu and selects a maker , the 2nd automatically fills up with models from that car maker only and it gets its information from the database.That is every time i decide to add a new model to my database the 2nd menu (if selected) must go and search the database for all the models for that maker and show them.

Here's the code:The first menu works. It goes into the database and selects all the cars from the makers table.However the 2nd menu shows me only  CHOOSE MODEL  and   ----------  .   It seems to have a problem in the second query when i say   WHERE MAKER_ID=$ID.




<?php
$count++;
setcookie("count", $count);
?>

<?php
echo ($count . ($count == 1 ? "visit" : " visits"));
echo(" <br>");

include ("pw.inc");
include ("functions.php3");
include ("info.inc");


$table="auto_makers";

$field_name="auto_maker";


function createSelect ( $field_name, $table, $Select = 0, $select_id="" ) {                       
global $db_name;                                                                                                                                                                                                                                                                                    
 

$conn = db_connect($db_host,$db_user,$db_pass,$db_name);
$query = "SELECT model_id, auto_maker FROM auto_makers";
$res= db_query($query,$conn);

    printf("<select name=\"$field_name\">\n");
  if ($Select == "0") { printf("<option \"\">Choose maker\n"); printf("<option \"\">--------\n");}

    while ($row = db_fetch_array($res,$nr) ):
  
    $id = $row["model_id"];
        $name = $row["auto_maker"];
        if ($id == $select_id) {
          printf("<option  SELECTED  value=\"$id\">$name\n");                                                  
          } else {
         printf("<option  value=\"$id\">$name\n");
        }
    endwhile;
    printf("</select>\n");

###########################################################


$table2="auto_models";
$field_name2="model";

      
        
                                                               
            
   echo ("<br>");
echo ("<br>");



function createSelect2 ( $field_name2, $table2, $Select = 0, $select_id="" ) {
global $db_name;

$conn = db_connect($db_host,$db_user,$db_pass,$db_name);
$query = "SELECT maker_id, model FROM auto_models where maker_id='$id'  ";
$res= db_query($query,$conn);

    printf("<select name=\"$field_name2\">\n");
    if ($Select == "0") { printf("<option \"\">Choose Model"); printf("<option \"\">--------\n");}

 while ($row= db_fetch_array($res,$nr) ):
        $maker_id = $row["maker_id"];
        $field_name2 = $row["model"];
       if ($maker_id == $select_id) {
        printf("<option  SELECTED value=\"$maker_id\">$name\n");
   } else {
           printf("<option  value=\"$maker_id\">$field_name2\n");
        }
    endwhile;
    printf("</select>\n");

  }}
  

?>  


<?php

#createSelect("FirstName","namedbase",1);

createSelect("auto_maker","");

createSelect2("model","");




?>    

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close