下拉菜单并搜索数据库 [英] Drop down menus and searching the DB

查看:80
本文介绍了下拉菜单并搜索数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先要说的是我对PHP / MySQL的新手......


我已经拥有一个充满信息的数据库。要查看我的数据库的外观以及设置方式,请参阅以下链接( www。 triplesource.net/db/


至于我到目前为止,这是我可以让我的下拉框做的...


http://www.triplesource.net/php/ )现在,这是从数据库中获取的,它从ROW年表中拉出来。怎么......我需要它来显示FIXED选项......(IE)( http://www.triplesource.net/php/year%20and%20make.htm )这是我想要的固定格式......现在我不知道该怎么办是代码它,以便PHP知道用户可以说选择 2004"和本田现在,一旦他们选择他们会点击提交按钮,然后搜索我的数据库并提取所有符合匹配的部分号码。 2004年本田我知道这是非常可能的我只是很新才能理解这么复杂的代码......我正在寻求其他人的帮助如果有人可以帮助我,那将真的很有帮助。

以下是我的代码示例


[PHP]<?php

//建立MySQL连接

include(''db functions / db_connect.php'');


echo''连接到数据库!'';


echo''< p>& nbsp;< / p>'';


echo"< select name = D1>" ;;

while($ row = mysql_fetch_array($ result)){


echo"< option value = $ row [YEAR]> ; $行[年] LT; / A>< /选项>英寸;

}

echo"< / select>" ;;

?>

[/ PHP]


这是我开始玩的第二个代码。


[PHP]<?php

//建立MySQL连接

include(''db functions / db_connect.php''' );


echo''连接到数据库!';


echo''< p>& nbsp;< / p为H. '';


$ sql =" SELECT id,year FROM Catalog" ;;

$ result = mysql_query($ sql);


$ options ="" ;;


while($ row = mysql_fetch_array($ result)){


$ id = $ row [" id" ]。

$ thing = $ row [" year"];

$ options。="< OPTION VALUE = \" $ id \">"。$ year。''< / option>'';

}

?> [/ PHP]


[HTML]< SELECT NAME = year>

< OPTION VALUE = 0>选择

<?= $ options?>

< / SELECT> [/ HTML]


先谢谢了!


克里斯

I would first like to say that I am very new to PHP/MySQL...

I have a database full of infomation already. to view what my database looks like and how it is set up please see the following link ( www.triplesource.net/db/ )

As far as what I have so far this is what I can get my drop down box to do...

( http://www.triplesource.net/php/) Now that is live from the DB it is pulling from the table from ROW "year" how ever... I need it to be showing FIXED options... (I.E.) ( http://www.triplesource.net/php/year%20and%20make.htm ) This is the fixed format I would like... Now the thing I dont know how to do is code it so that php will know the user lets say picked " 2004" and "Honda" now once they choice that they would click a Submit button that will then search my Database and pull all Part numbers that match " 2004 Honda" I know this is very possiable I am just very new to understand such a complex code... There for I am seeking help of others It would really be a grate help if someone can help me out please.

Here is the example of my code

[PHP]<?php
// Make a MySQL Connection
include (''db functions/db_connect.php'');

echo ''Connected to Database!'';

echo ''<p>&nbsp;</p>'';

echo "<select name=D1>";
while($row = mysql_fetch_array($result)){


echo "<option value=$row[YEAR]>$row[year]</a></option>";
}
echo "</select>";
?>
[/PHP]

and here is a second code I started to play with.

[PHP]<?php
// Make a MySQL Connection
include (''db functions/db_connect.php'');

echo ''Connected to Database!'';

echo ''<p>&nbsp;</p>'';

$sql="SELECT id, year FROM Catalog";
$result=mysql_query($sql);

$options="";


while ($row=mysql_fetch_array($result)) {

$id=$row["id"];
$thing=$row["year"];
$options.="<OPTION VALUE=\"$id\">".$year.''</option>'';
}
?> [/PHP]

[HTML]<SELECT NAME=year>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>[/HTML]


Thanks in advanced!

Chris

推荐答案

row = mysql_fetch_array(
row = mysql_fetch_array(


result)){



echo"< option value =
result)){


echo "<option value=


row [YEAR]>
row[YEAR]>


这篇关于下拉菜单并搜索数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆