Jump to content

Newbie question - updating SQL from drop down menu


emailuser

Recommended Posts

Hi , i am very new to php and am trying to change a php asset program to include another drop down menu ,

I have created the drop down and it shows the correct entries from Audit in sql , the process is that the user completes the php form for a new asset then clicks save to enter it to the database , the details below adds another drop down menu once they have selected the correct value i do not know how to capture this and write it back to the sql database ... help much appreciated ...

 

// $sql = 'SELECT * FROM audit';

// $res = mysql_query($sql) or die(mysql_error());

// while ($rec = mysql_fetch_assoc($res)) $desc[] = $rec;

 

  // die('<pre>'.print_r($desc));

 

// echo '<SELECT name="dropdown">';

// foreach ($desc as $c)

// {

//  if ($c['id'] == $_GET['id'])

  //    echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['desc']}</OPTION>\n";

  //  else

  //    echo "<OPTION value=\"{$c['id']}\">{$c['desc']}</OPTION>\n";

// }

// echo '</SELECT>';

You either need to do one of the following two:

1) An ajax call to update the database and then use javascript to add another populated dropdown (tricky)

2) Perform a "submit" and reload the same page after having parsed the information through PHP (preferred for your level)

If I have caught the right meaning, it's pretty simple actually, in php.

 

switch:

<?php

switch($dropdown)
case "a" :
      return /*sql statement*/ ;
case "b" :
      return /*sql statement*/ ;
case "c" :
      return /*sql statement*/ ;
?>

etc..

 

If I understood, that should work; if I got the wrong drift, please tell me.

 

Sam

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.