text, list box...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

text, list box...

Post by sguy »

the value can be showed in text box, but can’t show in the list box…
how to show the value in the list box???
thanks...

text box

Code: Select all

<input maxlength=40 size=40 name=fullname value="<? mysql_select_db($database, $conn);
		$result=mysql_query("select * from ".$DBprefix."signup where username = '$nickname'") ;
                $number_of_array = mysql_num_rows($result);
		while ($number_of_array = mysql_fetch_array($result)){
		echo "$number_of_array[fullname]"; 
		}				
?>">

list box

Code: Select all

<select name=status>
          <option value="" selected>Prefer undisclosed</option>
          <option value="Single" <?php if(isset($status)&&$status=='Single'){echo('selected');} ?>>Single</option>
          <option value="Living together" <?php if(isset($status)&&$status=='Living together'){echo('selected');} ?>>Living together</option>
          <option value="Married" <?php if(isset($status)&&$status=='Married'){echo('selected');} ?>>Married</option>
          <option value="Separated" <?php if(isset($status)&&$status=='Separated'){echo('selected');} ?>>Separated</option>
          <option value="Divorced" <?php if(isset($status)&&$status=='Divorced'){echo('selected');} ?>>Divorced</option>
          <option value="Widowed" <?php if(isset($status)&&$status=='Widowed'){echo('selected');} ?>>Widowed</option>
</select>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you forget to create $status? :?
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

when user register, he/she need to fill in all the details....
when he/she click "Edit Profile", all his/her personal details will show in textbox and listbox....
then he/she click "Update" button to save back to the database.

the textbox can be showed but i don't know how to retrieve the result in listbox...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$_POST['status']
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

it is not a button, i can post the value to the page that contain textbox & listbox, so i use while loop to select the value in the textbox...

but dont know how to use while loop to select in the listbox
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

The value will be like:

Code: Select all

<?php
if ($_POST['status'] == "Single")
?>
So at the arrival it is pretty much identical and the same process as the textbox should work fine.
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

Bill H wrote:The value will be like:

Code: Select all

<?php
if ($_POST['status'] == "Single")
?>
So at the arrival it is pretty much identical and the same process as the textbox should work fine.

not very understand....

can use the same method in list box?

Code: Select all

<input maxlength=40 size=40 name=fullname value="<? mysql_select_db($database, $conn); 
      $result=mysql_query("select * from ".$DBprefix."signup where username = '$nickname'") ; 
                $number_of_array = mysql_num_rows($result); 
      while ($number_of_array = mysql_fetch_array($result)){ 
      echo "$number_of_array[fullname]"; 
      }             
?>">
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Sorry, I thought I knew what you were asking, but apparently not.
I have no idea what you are trying to find out.
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

i've tried this on my own pc, it works....
when i upload to my web host, it doesn't work....
any problems???

Code: Select all

<? echo'<a class=hp href=edit.php?education='.urlencode($row[education]).'>Edit Profile</a>';?>

Code: Select all

<select name=education>
     <option value="" selected>Prefer undisclosed</option>
     <option value="High School"<?php if(isset($education)&&$education=='High School'){echo('selected');} ?>>High School</option>
     <option value="College"<?php if(isset($education)&&$education=='College'){echo('selected');} ?>>College</option>
     <option value="Bachelor"<?php if(isset($education)&&$education=='Bachelor'){echo('selected');} ?>>Bachelor</option>
     <option value="Master"<?php if(isset($education)&&$education=='Master'){echo('selected');} ?>>Master</option>
     <option value="PhD"<?php if(isset($education)&&$education=='PhD'){echo('selected');} ?>>PhD</option>
     <option value="Other"<?php if(isset($education)&&$education=='Other'){echo('selected');} ?>>Other</option>
</select>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what doesn't work about it?
User avatar
sguy
Forum Commoner
Posts: 61
Joined: Sun Aug 10, 2003 2:44 am

Post by sguy »

the drop down menu show the first value only...
"Prefer undisclosed"

should be same with the value in my database

in the first page, i pass the 'education' value (for example, Master) to second page, then the drop down menu should be Master...

it works on my own machine, but can't work in web host...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

<option value="" selected>Prefer undisclosed</option>
is the reason why the listbox doesn't work. Remove 'selected'
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

Code: Select all

<?php
<select name=education>
     <option value="" <?php if(!isset($_POST['education']) || $_POST['education']=='') {echo('selected');} ?>>Prefer undisclosed</option>
     <option value="High School"<?php if(isset($_POST['education']) && $_POST['education']=='High School') {echo('selected');} ?>>High School</option>

//etc
</select> 
?>
Post Reply