选择下拉框中的隐藏ID
I am working on another project that calls for a dropdown box to be populated with Salesman names. I have setup the database to pass the id
around, as opposed to the salesman's name. I want to know if there is a way to include a "hidden" column within a dropdown box, and call the id
as opposed to the name
.
There could possibly be salesman with the same first and last name, so I can't use a UNIQUE column to help (by using jQuery to re-query the database based on name
.
I'm open to suggestions if there might be a more appropriate way to do this. Thanks in advance!
function getSalesmen() {
include 'scripts/mysql_login_pdo.php';
$query = "SELECT `id`, `fname`, `lname` " .
"FROM `users` " .
"ORDER BY `fname` ASC";
$statement = $db->prepare($query);
$statement->execute();
$salesman = '';
while ($row = $statement->fetchObject()) {
$fname = $row->fname;
$lname = $row->lname;
$salesman .= '<option>';
$salesman .= $fname . ' ' . $lname; //This is where I'd like the ID to somehow be handled
$salesman .= '</option>';
}
$db = null;
return $salesman;
}
Relevant section of index.php-
<li>
<form method="post">
<ul>
<li>Salesman</li>
<li><select id="salesman" name="salesman"><?php print getSalesmen(); ?> </select></li>
<li>Status</li>
<li><select><?php print getStatus(); ?></select></li>
<li><button type="button" id="search_a" name="search_a">Search</button><br />
<button type="button" id="fill_all_a" name="fill_all_a">All Assigned Leads</button></li>
</ul>
</form>
</li>
我正在开发另一个项目,该项目要求使用Salesman名称填充下拉框。 我已经设置数据库来传递 可能有推销员使用相同的名字和姓氏,所以我不能使用UNIQUE列来帮助(通过使用jQuery基于 如果可能有更合适的方法,我愿意接受建议。提前致谢! p>
index.php的相关部分 - p>
\ n id code>,而不是推销员的名字。 我想知道是否有办法在下拉框中包含“隐藏”列,并调用
id code>而不是
name code>。 p> \ n
name code>重新查询数据库) 。 p>
function getSalesmen (){
include'scripts / mysql_login_pdo.php';
$ query =“SELECT`id`,`fname`,`lname`”。
“FROM`users`”。
“ORDER BY` fname` ASC“;
$ statement = $ db-&gt; prepare($ query);
$ statement-&gt; execute();
$ salesman ='';
而($ row = $ statement-&gt; fetchObject()){
$ fname = $ row-&gt; fname;
$ lname = $ row-&gt; lname;
$ salesman。='&lt; option&gt;' ;
$ salesman。= $ fname。''。$ lname; //这是我希望以某种方式处理ID的地方
$ salesman。='&lt; / option&gt;' ;
}
$ db = null;
return $ salesman;
}
code> pre>
&lt; li&gt;
&lt; form method =“post”&gt;
&lt; ul&gt;
&lt; li&gt; Salesman&lt; / li&gt;
&lt; li&gt;&lt; select id =“salesman”name =“salesman”&gt;&lt;?php print getSalesmen(); ?&GT; &lt; / select&gt;&lt; / li&gt;
&lt; li&gt;状态&lt; / li&gt;
&lt; li&gt;&lt; select&gt;&lt;?php print getStatus(); ?&gt;&lt; / select&gt;&lt; / li&gt;
&lt; li&gt;&lt; button type =“button”id =“search_a”name =“search_a”&gt;搜索&lt; / button&gt;&lt; br /&gt;
&lt; button type =“button”id =“fill_all_a”name =“fill_all_a”&gt;所有已分配的潜在客户&lt; / button&gt;&lt; / li&gt;
&lt; / ul&gt;
&lt; / form&gt;
&lt; ; / li&gt;
code> pre>
div>
Just use the value
attribute of your option
tag
$salesman .= '<option value="'.$row->id.'">';
$salesman .= $fname . ' ' . $lname;
$salesman .= '</option>';
Now the id
of the selected salesman will be posted.