dropdown list and value

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
pama
Forum Newbie
Posts: 12
Joined: Fri May 30, 2003 8:37 am

dropdown list and value

Post by pama »

i don't know how to send to database values from dropdown list:
i would like to make different values displayed on the page, and different on database. could you help me?

Code: Select all

<select size=1 name="txtCat">
    <?
$query = "SELECT c_name FROM estimatedacrs;";
	$mysql_result = query($query);
    while ($row = mysql_fetch_row($mysql_result)) &#123;
      if ($row&#1111;0] == $t_cat) &#123;
          print "                  <option value="$row&#1111;0]" selected>$row&#1111;0]</option>\n";
      &#125;
      else &#123;
        print "                  <option value="$row&#1111;0]">$row&#1111;0]</option>\n";
      &#125;
    &#125;
    ?>
	</select>
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

i dont really understand what you want to do. please be more specific.
pama
Forum Newbie
Posts: 12
Joined: Fri May 30, 2003 8:37 am

Post by pama »

in table estimatedacrs i have:
+------+--------------+-----------+
| c_id | c_number | c_name |
+------+--------------+-----------+
| 1 | 1 | <10 |
| 2 | 2 | 10...30 |
| 3 | 3 | >30...80 |
| 4 | 4 | >80...150 |
| 5 | 5 | >150 |
+------+--------------+-----------+
on the page in dropdown list are displaiyng values from c_name, but when user send form, in table result should be values from c_number....
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Is the:

query($query)

A method you have created ?

Regards,

To Add:

What is the value of $t_cat ?
pama
Forum Newbie
Posts: 12
Joined: Fri May 30, 2003 8:37 am

Post by pama »

$t_cat should be the same as c_number, and this value is store in table "result"...
tsathoggua
Forum Newbie
Posts: 2
Joined: Fri Jun 13, 2003 9:00 am

Post by tsathoggua »

Right. What you want is to be able to send values via the <option> tag other than the value that's actually IN the <option> tag.

If this is the case (and I'm sorry if I am jumping to conclusions) it's a HTML problem, not a PHP one.

Code: Select all

<form action='where.php' method='post'>
<select name='select_element'>
<option value='1'>Option One</option>
<option value='2'>Option Two</option>
<option value='3'>Option Three</option>
</select>
<input type='submit'>
</form>
If you submitted this form you would be submitting the value of the <option> tag, not the text contained between the tags.

Does this help?
pama
Forum Newbie
Posts: 12
Joined: Fri May 30, 2003 8:37 am

Post by pama »

not exactly, beacuse i would like to use values from database... :( this page is dynamically, not statically
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

cactus wrote:Is the:

query($query)

A method you have created ?

Regards
This question still is open...
tsathoggua
Forum Newbie
Posts: 2
Joined: Fri Jun 13, 2003 9:00 am

Re: dropdown list and value

Post by tsathoggua »

So? Try this.

Code: Select all

<select size=1 name="txtCat">
    <?
$query = "SELECT c_name, c_number FROM estimatedacrs;";
	$mysql_result = mysql_query($query);
    while ($row = mysql_fetch_row($mysql_result)) &#123;
      if ($row&#1111;0] == $t_cat) &#123;
          print "                  <option value="$row&#1111;1]" selected>$row&#1111;0]</option>\n";
      &#125;
      else &#123;
        print "                  <option value="$row&#1111;1]">$row&#1111;0]</option>\n";
      &#125;
    &#125;
    ?>
	</select>
Am I being really dense and missing something here? Sorry if I am.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

maybe this will help:

Code: Select all

<?php
$query = "SELECT c_number,c_name FROM estimatedacrs ORDER BY c_id DESC";

$result = MYSQL_QUERY($query);

while ($row = mysql_fetch_array($result)) {
	$c_number = $row['c_number'];
	$c_name = $row['c_name'];

	$list .= "<option value='$c_number'>$c_name</option>";
	}

$select_block = "<select>$list</select>";

print $select_block;
?>
Post Reply