PHP drop down return to previous selection -
ok small section of original code. have 2 pages page full of forms , boxes page puts information db.
oasis.php page right here code changes client name , code. on entire page. on change event.
$sql = "select * client_lookup order client_full_name asc"; $result = mysql_db_query ($dbname, $sql, $dblink); $options4=""; while ($row = mysql_fetch_array($result)) { $id=$row["client_code"]; $thing=$row["client_full_name"]; $options4.="<option value=\"$id, $thing\">".$thing; } ?> <form name="form" action="<?php echo $_server['php_self']; ?>" method="post"> <select name="clientnamefour" onchange="this.form.submit()"> <option value=0>client <?php echo $options4?> </select> </form>
once form below on oasis.php page submitted goes process page , puts information data base. once done have header returns me page. default client returned.
in attempt return selected client drop down used code. automatically select last selected client.
$sql = "select * client_lookup order client_full_name asc"; $result = mysql_db_query ($dbname, $sql, $dblink); session_start(); $current = isset($_session['clientnamefour']) ? $_session['clientnamefour'] : 0; $options4=""; while ($row = mysql_fetch_array($result)) { $id = $row["client_code"]; $value = $row["client_full_name"]; $key = "$id, $value"; $selected = ($id == @$_session['clientnamefour']) ? ' selected' : ''; $options4.="<option value=\"{$key}\"{$selected}>{$value}"; } ?> <form name="form" action="<?php echo $_server['php_self']; ?>" method="post"> <select name="clientnamefour" onchange="this.form.submit()"> <option value=0>client <?php echo $options4?> </select> </form>
this works onchange event doesn't not work! doesn't post itself. on change event key or whole page doesn't populate information.
you read $_session['clientnamefour']
never write it... think you're confusing $_session
$_post
. if used $_post
instead, $_post['clientnamefour']
value of <select>
<select>
has name attribute of 'clientnamefour'.
on side note, never manipulate variable $current
, - maybe php syntax i'm unfamiliar - when manipulate $_session['clientnamefour']
there's commercial @ character @
before $
...
Comments
Post a Comment