Page 1 of 1

dropdown list and value

Posted: Fri Jun 13, 2003 7:17 am
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>

Posted: Fri Jun 13, 2003 7:32 am
by Tubbietoeter
i dont really understand what you want to do. please be more specific.

Posted: Fri Jun 13, 2003 8:27 am
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....

Posted: Fri Jun 13, 2003 8:33 am
by cactus
Is the:

query($query)

A method you have created ?

Regards,

To Add:

What is the value of $t_cat ?

Posted: Fri Jun 13, 2003 8:50 am
by pama
$t_cat should be the same as c_number, and this value is store in table "result"...

Posted: Fri Jun 13, 2003 9:00 am
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?

Posted: Fri Jun 13, 2003 9:11 am
by pama
not exactly, beacuse i would like to use values from database... :( this page is dynamically, not statically

Posted: Fri Jun 13, 2003 9:58 am
by volka
cactus wrote:Is the:

query($query)

A method you have created ?

Regards
This question still is open...

Re: dropdown list and value

Posted: Fri Jun 13, 2003 10:52 am
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.

Posted: Fri Jun 13, 2003 11:08 am
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;
?>