Jump to content
Larry Ullman's Book Forums

Sticky Forms With Pull Down Menu Options


Recommended Posts

The below code generates a pull down menu list of names that user can select to use. It is one of many input options on the form including text and radio button form options. I am able to store all the other input options to be redisplayed in case of editing needs, but unable to redisplay the user selection from this signature pull down menu. When I return the user to this page currently the signature pull down menu is at the default start display, not the users choice.

 

Any suggestions would be appreciated.

 

<?php

 

require_once ('./php/mysql_connect.php'); // Connect to the db.

$cusid=$_SESSION['cusid'];

$query="SELECT relcusid, concat(authsign,'-',signtitle) as mysig FROM relsignor

WHERE relcusid=$cusid";

$result = mysql_query ($query);

echo "<select name = mysig value=''>mysig</option>";

 

while($nt=mysql_fetch_array($result)){//Array of records stored in $nt

echo '<option value=" ' . $nt["mysig"]. ' "> '. $nt["mysig"] .'</option>';

}

echo "</select>";

?>

<p><b>Signature to use: </b> </p><br />

<hr />

 

<div align="center"><input type="submit"

name="submit" value="Submit My Information" />

<input type="hidden" name="submitted" value="TRUE" />

</div>

Link to comment
Share on other sites

On page 550 of the 3rd edition, Larry states:

 

"The first time the administrator runs this script, there will be no existing artists. In this case, there won't be any options in this pull-down menu, so an indication to add an artist is made (FIgure 17.15).

This otherwise-basic code is complicated by the desire to make the pull-down menu sticky. To make any select menu sticky, you have to add selected="selected" to the proper option. So the code in the while loop checks if $_POST['existing'] is set and, if so, if its value is the same as the current artist ID being added to the menu."

 

On the same page, Larry uses the following code, which can easily be adapted to your needs:

 

while ($row = mysqli_fetch_array($r,MYSQLI_NUM)) {

 echo "<option value=\"$row[0]\"";

 if (isset($_POST['existing']) && ($_POST['existing'] == $row[0])) {

   echo ' selected="selected"';

 }

 echo ">$row[1]</option>\n";

}

 

Well, hope that helps.

  • Upvote 1
Link to comment
Share on other sites

  • 2 weeks later...

Okay, I have modified my code based on Larry's process on page 550, but am getting the error:

//Warning: mysql_fetch_array() expects parameter 2 to be long, string given in C:\xampp\htdocs\preview_setup_AZ_state_form.php on line 343. Line 343 is the while condition line.

 

I can't rely on post I don't think, because my user editing option occurs a few screens later, when they have an option to make changes based on a new display of information so that is why is am using SESSION instead of POST. Any suggestions for corrections would be appreciated.

 

<p><b>Signee to use for this form: </b> </p><br />

<?php

 

require_once ('./php/mysql_connect.php'); // Connect to the db.

$cusid=$_SESSION['cusid'];

$query="SELECT relcusid, concat(authsign,'-',signtitle) as mysig FROM relsignor

WHERE relcusid=$cusid";

 

$result = mysql_query ($query);

 

if (mysql_num_rows($result) > 0) {

while($row=mysql_fetch_array($result, mysql_num )) {

echo '<option value=\"$row[0]\"';

if ($_SESSION['my_sig'] == $row) {echo 'selected="selected"';

echo ">$row[1]</option>\n";

}

}

}

Mahalo

Link to comment
Share on other sites

  • 1 year later...

I am a little confused by this piece of code still. Iff one were to have multiple pull down menus (entering say a new artist really not necc) what changes are made? I like the sticky option and think the radio could be dropped. Each menu has its own query so free result used between each menu? Thanks for any suggestions.

 

Link to comment
Share on other sites

I've been having similar discussions with a fellow board member recently, and I'm starting to think more and more that serializing data to be used in sticky forms (while not relationally sound) isn't such a bad idea.

 

For example, instead of having a separate table or tables for each drop-down lists data, it's a lot more efficient to stick all the data together into one string in one field in a DB. Of course, you'd have to delimit the string somehow so that you can easily split up and reassemble the data for the application and DB, but it seems like it'd save a lot of trouble with having to make too many queries just to make a form sticky.

 

If you meant something else by your post, BHB, please say so.

Link to comment
Share on other sites

Appears my drop downs are working and the mult queries seem to be happy.. . Might confuse the ids to have one long query. I used a modules foldure from advanced 5 and the redirect path (since my page is an include ). The form path in combination with redirect seem to be causing form not to process and loose the sticky! I am going to step away from the code and work on graphics for a while... Hope subconscious works it out.

Link to comment
Share on other sites

this part look right?

 

If(isset($_GET[submitted])) {

$url .= ' &submitted=' . urlencode($_GET['name1=question&name2=level&name3=industry']);

}

 

 

I am confused about the data. Dropp menu is the value from id (two tables level and industry each have respective id). The final post to db should be the id not the value. So maybe I need to add more values to the URL.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...