Dropdownbox read from Mysql to PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas j

    #1

    Dropdownbox read from Mysql to PHP

    Hi,

    I have a MySqlBase with a tabel named CARS and with 3 fields;
    CarsType, CarsModel, CarsInfo.
    Now I want to generate 2 dropdownboxes in PHP read from CARS.
    First I will "load" CarsType into an dropdownbox, and then I make a
    choice, exampel FORD, now the next dropdownbox (CarsModel) will show
    Escort, Sierra and so...
    Finally I will make a "actionbutt on" named showinfo and when I click
    it will show CarsInfo.

    Can anybody help me ?

    Best regards and thanks

    Thomas J, Denmark.
    Not so good at english..hope you understand..
  • Tim Van Wassenhove

    #2
    Re: Dropdownbox read from Mysql to PHP

    In article <60cd8fbb.04050 50947.72bc64c7@ posting.google. com>, thomas j wrote:[color=blue]
    > Hi,
    >
    > I have a MySqlBase with a tabel named CARS and with 3 fields;
    > CarsType, CarsModel, CarsInfo.
    > Now I want to generate 2 dropdownboxes in PHP read from CARS.
    > First I will "load" CarsType into an dropdownbox, and then I make a
    > choice, exampel FORD, now the next dropdownbox (CarsModel) will show
    > Escort, Sierra and so...
    > Finally I will make a "actionbutt on" named showinfo and when I click
    > it will show CarsInfo.[/color]

    Here is pseudocode that does what you want, translation to php i leave
    to you ;)

    In all the cases you have to know all the types to generate the first
    selectbox

    check if a type was selected:

    no: ready.

    yes:

    get all the models for the selected type and generate 2nd
    selectbox

    check if a model was selected:

    no: ready.

    yes:
    get info for selected model and type and show this.


    --

    Comment

    • RotterdamStudents

      #3
      Re: Dropdownbox read from Mysql to PHP

      > I have a MySqlBase with a tabel named CARS and with 3 fields;[color=blue]
      > CarsType, CarsModel, CarsInfo.
      > Now I want to generate 2 dropdownboxes in PHP read from CARS.
      > First I will "load" CarsType into an dropdownbox, and then I make a
      > choice, exampel FORD, now the next dropdownbox (CarsModel) will show
      > Escort, Sierra and so...
      > Finally I will make a "actionbutt on" named showinfo and when I click
      > it will show CarsInfo.
      >
      > Can anybody help me ?
      >
      > Best regards and thanks[/color]


      The firts php file (carstype.php for example) should look like this. It will
      list the types of cars in the db into a dropdownbox:
      =============== =============== =============== =============== =============== =
      ======
      <?php
      require "cars.inc.p hp";
      $cars_db = cars_connecte_d b();


      $str_requete = "SELECT CarsType FROM cars ORDER BY CarsType ASC";

      $result_article s = mysql_query ($str_requete,$ cars_db) or
      cars_mysql_die( );

      print ('<form method=post action=carsmode l.php><select name=CarsType>' );

      while ($articleDb =mysql_fetch_ob ject($result_ar ticles))
      {
      print("
      <option
      value='$article Db->CarsType'>$art icleDb->CarsType</option>

      ");
      }

      print ('</select>
      <input type=submit name=send value=Send>
      </form>');

      ?>

      =============== =============== =============== =============== =============== =
      ======

      The second file (carsmodel.php for example) should look like this. It will
      list the models of the cartype you have selected in carstype.php in a
      dropbox

      =============== =============== =============== =============== =============== =
      =======
      <?php
      require "cars.inc.p hp";
      $cars_db = cars_connecte_d b();


      $str_requete = "SELECT CarsModel,CarsT ype FROM cars WHERE
      CarsType='$Cars Type' ORDER BY CarsModel ASC";

      $result_article s = mysql_query ($str_requete,$ cars_db) or
      cars_mysql_die( );

      print ('<form method=post action=carsinfo .php><select name=CarsModel> ');

      while ($articleDb =mysql_fetch_ob ject($result_ar ticles))
      {
      print("
      <option
      value='$article Db->CarsModel'>$ar ticleDb->CarsModel</option>

      ");
      }

      print ('</select>
      <input type=submit name=send value=Send>
      </form>');

      ?>
      =============== =============== =============== =============== ==========

      The third file with the result should than look like
      =============== =============== =============== =============== ==========
      <?php
      $db = mysql_connect(" localhost","use rname","passwor d");
      mysql_select_db ("databasename" ,$db);

      $sql = mysql_query("SE LECT CarsModel,CarsT ype,CarsInfo FROM cars WHERE
      CarsModel='$Car sModel'");

      $sql_doublechec k = mysql_query("SE LECT CarsModel,CarsT ype FROM contacts
      WHERE CarsModel='$Car sModel' AND CarsType='$Cars Type'");
      $doublecheck = mysql_num_rows( $sql_doublechec k);

      if($doublecheck == 0){
      echo "<strong><f ont color=red>The info you requested is not
      available!</font></strong>";
      } elseif ($doublecheck > 0) {
      echo "The information of the car "$CarsInfo$ "";
      }

      ?>
      =============== =============== =============== =============== =============== =
      =============== =
      The contents of cars.inc.php
      =============== =============== =============== =============== =============== =
      =============== =
      <?php

      function cars_mysql_die( $error = "")
      {
      if (empty($error))
      {
      $mysqlError = mysql_error();
      if (!empty($mysqlE rror))
      {
      echo "SQL server reply: ".$mysqlErr or;
      }
      }
      else
      echo "SQL server reply: ".$error;
      echo "<br><a href=\"javascri pt:history.go(-1)\">Terug</a>";
      exit;
      }


      function cars_connecte_d b()
      {
      // Server connection parameter
      require "cars.conf.php" ;

      $db = mysql_connect($ host,$login,$pa ssword) or cars_mysql_die( );
      mysql_select_db ($base);
      return $db;
      }

      ?>
      =============== =============== =============== =============== =============== =
      =============== ===
      The contents of cars.conf.php
      =============== =============== =============== =============== =============== =
      =============== ===
      <?php
      // configuration of my database
      $host = "localhost" ;
      $login= "username";
      $base = "databasena me";
      $password="pass word";
      ?>
      =============== =============== =============== =============== =============== =
      =============== ===

      --
      RotterdamStuden ts
      -------------------------------
      Dulce est despirere loco
      (Horatius, "Oden" 4,12,28)


      Comment

      • thomas j

        #4
        Re: Dropdownbox read from Mysql to PHP

        Hi,
        Thanks.
        It almost working fine;
        But I get an:
        Parse error: parse error, expecting `','' or `';'' in carsinfo.php on line 15

        (line with elseIf)

        Can You help me ?
        Thanks.
        Thomas J.


        [color=blue]
        > =============== =============== =============== =============== ==========
        >
        > The third file with the result should than look like
        > =============== =============== =============== =============== ==========
        > <?php
        > $db = mysql_connect(" localhost","use rname","passwor d");
        > mysql_select_db ("databasename" ,$db);
        >
        > $sql = mysql_query("SE LECT CarsModel,CarsT ype,CarsInfo FROM cars WHERE
        > CarsModel='$Car sModel'");
        >
        > $sql_doublechec k = mysql_query("SE LECT CarsModel,CarsT ype FROM contacts
        > WHERE CarsModel='$Car sModel' AND CarsType='$Cars Type'");
        > $doublecheck = mysql_num_rows( $sql_doublechec k);
        >
        > if($doublecheck == 0){
        > echo "<strong><f ont color=red>The info you requested is not
        > available!</font></strong>";
        > } elseif ($doublecheck > 0) {
        > echo "The information of the car "$CarsInfo$ "";
        > }
        >
        > ?>[/color]

        Comment

        • Andy Hassall

          #5
          Re: Dropdownbox read from Mysql to PHP

          On 7 May 2004 13:28:39 -0700, tjodense@ofir.d k (thomas j) wrote:
          [color=blue][color=green]
          >> echo "The information of the car "$CarsInfo$ "";[/color]
          >
          >It almost working fine;
          >But I get an:
          >Parse error: parse error, expecting `','' or `';'' in carsinfo.php on line 15
          >
          >(line with elseIf)[/color]

          Look at the quotes you have on the line remaining above. This will cause a
          parse error.

          --
          Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
          http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

          Comment

          • thomas j

            #6
            Re: Dropdownbox read from Mysql to PHP

            Now, I not getteing an ParseError, but now I can get no CarsInfo, even
            there is data in my field CarsInfo. It Allways say "No Information
            about the car"
            Maybe it is the value/My choice from CarsModel.php that not being
            "taking over" to CarsInfo.php.

            Thanks
            Thomas J.

            Andy Hassall <andy@andyh.co. uk> wrote in message news:<5t3o9057k 33iasnvutsr6759 2c1k5tuv36@4ax. com>...[color=blue]
            > On 7 May 2004 13:28:39 -0700, tjodense@ofir.d k (thomas j) wrote:
            >[color=green][color=darkred]
            > >> echo "The information of the car "$CarsInfo$ "";[/color]
            > >
            > >It almost working fine;
            > >But I get an:
            > >Parse error: parse error, expecting `','' or `';'' in carsinfo.php on line 15
            > >
            > >(line with elseIf)[/color]
            >
            > Look at the quotes you have on the line remaining above. This will cause a
            > parse error.[/color]

            Comment

            • Phil Powell

              #7
              Re: Dropdownbox read from Mysql to PHP

              You are better off loading all of them into arrays, from there you
              will populate Javascript arrays that will be loaded from the client.

              It's faster and more efficient, quick grab and go.

              Ha det bra!

              Phil

              tjodense@ofir.d k (thomas j) wrote in message news:<60cd8fbb. 0405050947.72bc 64c7@posting.go ogle.com>...[color=blue]
              > Hi,
              >
              > I have a MySqlBase with a tabel named CARS and with 3 fields;
              > CarsType, CarsModel, CarsInfo.
              > Now I want to generate 2 dropdownboxes in PHP read from CARS.
              > First I will "load" CarsType into an dropdownbox, and then I make a
              > choice, exampel FORD, now the next dropdownbox (CarsModel) will show
              > Escort, Sierra and so...
              > Finally I will make a "actionbutt on" named showinfo and when I click
              > it will show CarsInfo.
              >
              > Can anybody help me ?
              >
              > Best regards and thanks
              >
              > Thomas J, Denmark.
              > Not so good at english..hope you understand..[/color]

              Comment

              Working...