如何从php获取sql id值并使其成为php比较器? [英] How to get sql id value from php and make it become php comparator?
本文介绍了如何从php获取sql id值并使其成为php比较器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取mysql表的值并将其作为php中的比较器...
这是我的示例sql表和php代码:
| | id | | | pid | | | category | | |
| | 1 | | | 0 | | | < td> animal| |
| | 2 | | | 0 | | | 水果 | | |
| | 3 | | | 1 | | | rabbit | | |
| | 4 | | | 2 | | | lemon | | |
$ category_id = $ _REQUEST [' ID 跨度>]; // 从其他页面解析的选项值的ID
$ sql_pid = SELECT pid FROM table WHERE id ='。$ category_id。 ';
$ result_pid = mysql_query($ sql_pid);
if ($ result_pid == 0){
echo < select id ='show'>;
echo < option value =' '> - 请选择 - < / option>;
echo < / select> 跨度>;
}
else {
$ sql_category = SELECT * FROM table WHERE pid ='。$ category_id。 ';
$ result_category = mysql_query($ sql_category);
echo < select id ='显示'>中跨度>;
while($ row_category = mysql_fetch_array($ result_category)){
echo < option value ='。$ row_category [' id']。 '>。$ row_category [< span class =code-string>' category']。 < /选项>中跨度>;
}
echo < /选择> 中跨度>;
}
else {}内的查询函数工作正常但不适用于函数内部if($ result_pid == 0){} ..
哪里我做错了?我的方法是调用方法if($ result_pid == 0)?或者?
任何人都可以帮助我...
解决方案
category_id =
< blockquote> _REQUEST [' id']; // 从其他页面解析的选项值的ID
sql_pid
= SELECT pid FROM表WHERE id ='。
I want to get the value of mysql table and make it as a comparator in php...
Here is my example sql table and php code:
| | id | | | pid | | | category | | |
| | 1 | | | 0 | | | animal | | |
| | 2 | | | 0 | | | fruit | | |
| | 3 | | | 1 | | | rabbit | | |
| | 4 | | | 2 | | | lemon | | |
$category_id = $_REQUEST['id']; //id of option value parsing from another page
$sql_pid = "SELECT pid FROM table WHERE id = '".$category_id."'";
$result_pid = mysql_query($sql_pid);
if ($result_pid == 0) {
echo "<select id='show'>";
echo"<option value=''>--Please Choose--</option>";
echo "</select>";
}
else {
$sql_category = "SELECT * FROM table WHERE pid = '".$category_id."'";
$result_category = mysql_query($sql_category);
echo "<select id='show'>";
while($row_category = mysql_fetch_array($result_category)){
echo "<option value='".$row_category['id']."'>".$row_category['category']."</option>";
}
echo "</select>";
}
The query function inside the else{} work fine but not for the function inside if ($result_pid == 0) {}..
where I'm doing wrong? Is my way of calling the method if ($result_pid == 0)? or?
Can anyone help me please...
解决方案
category_id =
_REQUEST['id']; //id of option value parsing from another page
sql_pid = "SELECT pid FROM table WHERE id = '".
这篇关于如何从php获取sql id值并使其成为php比较器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文