 |
พี่ๆ ช่วยหน่อยค่ะ ทำ search listbox หลายตัวไม่ได้นะคะ |
|
 |
|
|
 |
 |
|
แบบว่าพอดีทำได้แต่คิดแบบง่ายๆ นะค่ะ เลยอยากได้คำแนะนำที่เขียนแว้วไม่งงหรือยาวเท่านี่นะค่ะ
search.php
<form name="form4" method="post" action="search_pro.php">
<p>
<select name=" projec_sys" id=" projec_sys">
<option value="">เทคโนโลยีการแสดงภาพ</option>
<option value="LCD">LCD</option>
<option value="DLP">DLP</option>
</select>
</p>
<p>
<select name="resolution" id="resolution">
<option value="">ความละเอียด Resolution</option>
<option value="UXGA (1,600 x 1,200)">UXGA (1,600 x 1,200)</option>
<option value="SXGA (1,280 x 1,024)">SXGA (1,280 x 1,024)</option>
<option value="WXGA (1,280 x 800)">WXGA (1,280 x 800)</option>
<option value="XGA (1,024 x 768)">XGA (1,024 x 768)</option>
<option value="SVGA (800 x 600)">SVGA (800 x 600)</option>
<option value="HD (1,920 x 1,080)">HD (1,920 x 1,080)</option>
</select>
</p>
<p>
<select name="bright" id="bright">
<option value="">ความสว่าง Ansi Lumens</option>
<option value="1">1-2,000</option>
<option value="2">2,001-3,000</option>
<option value="3">3,001-4,000</option>
<option value="4">4,001-5,000</option>
</select>
</p>
<p>
<label></label>
<select name="weight" id="weight">
<option value="">น้ำหนัก Weight (Kg)</option>
<option value="1">0-1.00</option>
<option value="2">1.01-2.00</option>
<option value="3">2.01-3.00</option>
<option value="4">3.01-4.00</option>
<option value="5">4.01-5.00</option>
</select>
</p>
<p>
<input type="submit" name="button" id="button" value="Search">
</p>
</form>
search_pro.php
if($bright==1){
if($weight==1){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 1 and 2000 && weight between 0 and 1.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==2){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 1 and 2000 && weight between 1.01 and 2.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==3){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 1 and 2000 && weight between 2.01 and 3.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==4){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 1 and 2000 && weight between 3.01 and 4.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==5){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 1 and 2000 && weight between 4.01 and 5.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
else{
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 1 and 2000");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
}
elseif($bright==2){
if($weight==1){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 2001 and 3000 && weight between 0 and 1.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==2){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 2001 and 3000 && weight between 1.01 and 2.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==3){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 2001 and 3000 && weight between 2.01 and 3.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==4){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 2001 and 3000 && weight between 3.01 and 4.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==5){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 2001 and 3000 && weight between 4.01 and 5.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
else{
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 2001 and 3000");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
}
elseif($bright==3){
if($weight==1){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 3001 and 4000 && weight between 0 and 1.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==2){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 3001 and 4000 && weight between 1.01 and 2.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==3){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 3001 and 4000 && weight between 2.01 and 3.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==4){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 3001 and 4000 && weight between 3.01 and 4.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==5){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 3001 and 4000 && weight between 4.01 and 5.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
else{
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 3001 and 4000");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
}
elseif($bright==4){
if($weight==1){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 4001 and 5000 && weight between 0 and 1.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==2){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 4001 and 5000 && weight between 1.01 and 2.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==3){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 4001 and 5000 && weight between 2.01 and 3.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==4){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 4001 and 5000 && weight between 3.01 and 4.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==5){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 4001 and 5000 && weight between 4.01 and 5.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
else{
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && bright between 4001 and 5000");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
}
else{
if($weight==1){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && weight between 0 and 1.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==2){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && weight between 1.01 and 2.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==3){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && weight between 2.01 and 3.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==4){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && weight between 3.01 and 4.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
elseif($weight==5){
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%' && weight between 4.01 and 5.00");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
else{
$query=mysql_query("SELECT * from product WHERE projec_sys like '%$projec%' && resolution like '%$resolution%'");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
}
}
จะติดที่ตัว search เป็นแบบช่วงนะค่ะ แต่ในsql เป็นค่าตัวเลขตัวเดียว เลยต้องนำมา if else หลายรอบนะค่ะ ช่วยแนะนำด้วยนะค่ะ อยากได้แนวคิดโค้ดดีๆนะค่ะ ขอบคุณล่วงหน้าค้า................ง
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-10-28 14:12:20 |
By :
sangkheb |
View :
1315 |
Reply :
11 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
search_pro.php
<?
if($bright==1){ $bright2=" and (bright between 1 and 2000 )"}
if($bright==2){ $bright2=" and (bright between 2001 and 3000 )"}
if($bright==3){ $bright2=" and (bright between 3001 and 4000 )"}
if($bright==4){ $bright2=" bright (between 4001 and 5000 )"}
if($weight==1){$weight2=" and (weight between 0 and 1.00 ) "}
if($weight==2{$weight2=" and (weight between 1.01 and 2.00 ) "}
if($weight==3{$weight2=" and (weight between 2.01 and 3.00 ) "}
if($weight==4{$weight2=" and (weight between 3.01 and 4.00 )"}
if($weight==5{$weight2=" and (weight between 4.01 and 5.00 )"}
$query=mysql_query("SELECT * from product WHERE projec_sys like '%".$projec."%' and resolution like '%".$resolution."%' ".$bright2." ".$weight2." ");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
|
 |
 |
 |
 |
Date :
2009-10-28 14:48:46 |
By :
Sek-Artdrinker |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้อีกแล้วค่ะพี่ T_T ทำไงดีอ่ะ ช่วยด้วยค่ะ
|
 |
 |
 |
 |
Date :
2009-10-28 15:24:56 |
By :
sangkheb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
if($bright==1){ $bright2=" and ";}
if($bright==2){ $bright2=" and bright between 1 and 2000";}
if($bright==3){ $bright2=" and bright between 2001 and 3000";}
if($bright==4){ $bright2=" and bright between 3001 and 4000";}
if($bright==5){ $bright2=" and bright between 4001 and 5000";}
if($weight==1){$weight2=" and ";}
if($weight==2){$weight2=" and weight between 0 and 1.00";}
if($weight==3){$weight2=" and weight between 1.01 and 2.00";}
if($weight==4){$weight2=" and weight between 2.01 and 3.00";}
if($weight==5){$weight2=" and weight between 3.01 and 4.00";}
if($weight==6){$weight2=" and weight between 4.01 and 5.00";}
$query=mysql_query("SELECT * from product WHERE projec_sys like '%".$projec."%' and resolution like '%".$resolution."%' ".$bright2." ".$weight2." ");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
}
ทำแบบนี้นะค่ะ แล้วมันขึ้น error ว่า
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\thaibiz_project\search_pro.php on line 37
บรรทัดที่เป็น $query นะค่ะ
พอดีลืมบอกไปค่ะว่าจะมีค่าว่างด้วย ตอนนี้ให้เป็น 1 ค่ะ ของแต่ละ list box
|
 |
 |
 |
 |
Date :
2009-10-28 15:35:25 |
By :
sangkheb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
echo "SELECT * from product WHERE projec_sys like '%".$projec."%' and resolution like '%".$resolution."%' ".$bright2." ".$weight2." ";
ออกมาดูด้วยครับ ว่ามันได้อาราย ออกมา
|
 |
 |
 |
 |
Date :
2009-10-28 16:00:45 |
By :
Sek-Artdrinker |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
<p>
<select name="bright" id="bright">
<option value="1">ความสว่าง Ansi Lumens</option>
<option value="2">1-2,000</option>
<option value="3">2,001-3,000</option>
<option value="4">3,001-4,000</option>
<option value="5">4,001-5,000</option>
</select>
</p>
<p>
<label></label>
<select name="weight" id="weight">
<option value="1">น้ำหนัก Weight (Kg)</option>
<option value="2">0-1.00</option>
<option value="3">1.01-2.00</option>
<option value="4">2.01-3.00</option>
<option value="5">3.01-4.00</option>
<option value="6">4.01-5.00</option>
</select>
</p>
อ๋อมันมาจากตรงนี่นะค่ะ คือว่าถ้าไม่ได้เลือกอะไรเลย จะเป็นค่าว่างนะค่ะเลยกำหนดให้ list box เป็น 1 นะค่ะ ถูกไหมค่ะเนี่ย เอ๋เข้าใจถูกไหมค่ะ แบบว่าถ้าไม่ได้เลือกอะไรเลยนะค่ะ มันต้องเช็คได้เช่นกันนะค่ะ รบกวนด้วยนะค่ะ
|
 |
 |
 |
 |
Date :
2009-10-28 16:01:35 |
By :
sangkheb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้เอ๋แก้ได้แล้ว ค่ะ
ขอบคุณพี่มากนะค่ะ ที่มาช่วยแก้ปัญหาให้ ปวดหัวแย่เลย อิอิ
ได้แนวคิดใหม่อีกแล้ว ขอบคุณมากๆ เลยค่ะ
|
 |
 |
 |
 |
Date :
2009-10-28 16:06:02 |
By :
sangkheb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในหน้า search_pro.php
ลองใส่แบบนี้ครับ อันนี้ผมใช้กับ เว็บผม ซึ่งหาข้อมูล แบบ list หลายๆ อันเหมือนกันครับ
ซึ่งอาจจะต้องมีปรับแก้บางจุดครับ
Code (PHP)
<?
// หาจากชื่อเทคโนโลยีแสดงภาพ
if($project_sys<>''){$project=" project_sys like '$project_sys' ";}
else {$project=" project_sys <> ' ' ";}
// หาจากขนาด
if($resolution=''){$project_re=" ('$project' ) ";}
else{$project_re=" '$project ' and ($resolution like '$resolution') ";}
// หาจากความสว่าง
if($bright=''){$project_re_bri="('$project_re')" ;}
else{$project_re_bri=" '$project_re' and (bright like '$bright ' )";}
// หาจากน้ำหนัก
if($weight=''){$project_re_bri_wei=" (' $project_re_bri')" ;}
else{$project_re_bri_wei=" (' $project_re_bri' and (weight like ' $weight')" ;}
$query=mysql_query("SELECT * from product WHERE '$project_re_bri_wei' ");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>';
?>
|
 |
 |
 |
 |
Date :
2009-10-28 16:13:50 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ในหน้า search_pro.php
ลองใส่แบบนี้ครับ อันนี้ผมใช้กับ เว็บผม ซึ่งหาข้อมูล แบบ list หลายๆ อันเหมือนกันครับ
ซึ่งอาจจะต้องมีปรับแก้บางจุดครับ
Code (PHP)
<?
// หาจากชื่อเทคโนโลยีแสดงภาพ
if($project_sys<>''){$project=" project_sys like '$project_sys' ";}
else {$project=" project_sys <> ' ' ";}
// หาจากขนาด
if($resolution=''){$project_re=" ('$project' ) ";}
else{$project_re=" '$project ' and ($resolution like '$resolution') ";}
// หาจากความสว่าง
if($bright=''){$project_re_bri="('$project_re')" ;}
else{$project_re_bri=" '$project_re' and (bright like '$bright ' )";}
// หาจากน้ำหนัก
if($weight=''){$project_re_bri_wei=" (' $project_re_bri')" ;}
else{$project_re_bri_wei=" (' $project_re_bri' and (weight like ' $weight')" ;}
$query=mysql_query("SELECT * from product WHERE '$project_re_bri_wei' ");
while($arr_product=mysql_fetch_array($query)){
echo $arr_product['name'].'<br>'; }
?>
|
 |
 |
 |
 |
Date :
2009-10-28 16:17:53 |
By :
tingtongkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณนะค่ะ ทุกคำตอบ จะลองไปนัดแปลงใช้ดูค่ะ ขอบคุณมากๆๆๆๆๆๆๆๆๆๆๆเลยค่ะ
|
 |
 |
 |
 |
Date :
2009-10-28 16:45:24 |
By :
sangkheb |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|