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
pama
Forum Newbie
Posts: 12 Joined: Fri May 30, 2003 8:37 am
Post
by pama » Fri Jun 13, 2003 7:17 am
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)) {
if ($rowї0] == $t_cat) {
print " <option value="$rowї0]" selected>$rowї0]</option>\n";
}
else {
print " <option value="$rowї0]">$rowї0]</option>\n";
}
}
?>
</select>
Tubbietoeter
Forum Contributor
Posts: 149 Joined: Fri Mar 14, 2003 2:41 am
Location: Germany
Post
by Tubbietoeter » Fri Jun 13, 2003 7:32 am
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 » Fri Jun 13, 2003 8:27 am
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....
cactus
Forum Regular
Posts: 343 Joined: Tue Jun 10, 2003 4:16 am
Location: UK
Post
by cactus » Fri Jun 13, 2003 8:33 am
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 » Fri Jun 13, 2003 8:50 am
$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 » Fri Jun 13, 2003 9:00 am
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 » Fri Jun 13, 2003 9:11 am
not exactly, beacuse i would like to use values from database...
this page is dynamically, not statically
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Jun 13, 2003 9:58 am
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
Post
by tsathoggua » Fri Jun 13, 2003 10:52 am
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)) {
if ($rowї0] == $t_cat) {
print " <option value="$rowї1]" selected>$rowї0]</option>\n";
}
else {
print " <option value="$rowї1]">$rowї0]</option>\n";
}
}
?>
</select>
Am I being really dense and missing something here? Sorry if I am.
redhair
Forum Contributor
Posts: 300 Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:
Post
by redhair » Fri Jun 13, 2003 11:08 am
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;
?>