การแสดงผลข้อมูล ต้องการให้แสดง แค่ ข้อมูลที่ส่งค่ามาเท่านั้น ต้องเขียน if else ประมาณไหนครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา การแสดงผลข้อมูล ต้องการให้แสดง แค่ ข้อมูลที่ส่งค่ามาเท่านั้น ต้องเขียน if else ประมาณไหนครับ

การแสดงผลข้อมูล ต้องการให้แสดง แค่ ข้อมูลที่ส่งค่ามาเท่านั้น ต้องเขียน if else ประมาณไหนครับ
ต้องการแสดงแค่ ที่ไม่ขีดเส้นใต้อ่าครับ ต้อง if else ประมาณ






หน้าส่งค่า
<form id="form1" name="form1" method="post" action="test1.php">
 <h3><font color="#09ba32">ประเภทอาหาร</font></h3>
 <table class="table table-hover"  width="100%" border="0" cellspacing="0" cellpadding="0">  
     <tr > 
        <td><input type="checkbox" name="res[]" value="ก๋วยเตี๋ยว"/>
            <span class="style1">ก๋วยเตี๋ยว</span></td>
        <td><input type="checkbox" name="res[]" value="สุกี้ชาบู"/>
            <span class="style1">สุกี้ ชาบู</span></td>
        <td><input type="checkbox" name="res[]" value="ร้านกาแฟ"/>
            <span class="style1">ร้านกาแฟ</span></td>
        <td><input type="checkbox" name="res[]" value="หมูกะทะ"/>
            <span class="style1">หมูกะทะ</span></td>
        <td><input type="checkbox" name="res[]" value="สเต็ก"/>
            <span class="style1">สเต็ก</span></td>
        <td><input type="checkbox" name="res[]" value="อาหารทะเล"/>
            <span class="style1">อาหารทะเล</span></td>

      </tr>
      </table>

      <table class="table table-hover" width="100%" border="0" cellspacing="0" cellpadding="0">
    <br>  
        <h3><font color="#09ba32">สิ่งอำนวยความสะดวก</font></h3>
      <tr>
        <td><input  type="checkbox" name="facilities[]" value="ที่จอดรถ"/>
            <span class="style1">ที่จอดรถ</span></td>
        <td><input type="checkbox" name="facilities[]" value="ห้องแอร์"/>
            <span class="style1">ห้องแอร์</span></td>
        <td><input type="checkbox" name="facilities[]" value="Wi-Fi"/>
            <span class="style1">Wi-Fi</span></td>
        <td><input type="checkbox" name="facilities[]" value="คาราโอเกะ"/>
            <span class="style1">คาราโอเกะ</span></td>
        <td><input type="checkbox" name="facilities[]" value="ดนตรี"/>
            <span class="style1">ดนตรี</span></td>
            </tr>
        </table>


       <div align="center"><input  class="btn btn-success" type="submit" name="Submit" id="Submit" value="ค้นหาข้อมูล" /></div>
มีต่อ ตรงคอมเม้นครับ


Jame Panuwat Suksamran 182.53.213.xxx 29-01-2017 18:16:30

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
หน้ารับค่าและแสดงผลครับ 
<?
    
  if ( isset( $_POST[res] ) )//รับค่าประเภทอาหาร
  {
   for($i=0;$i<count($_POST["res"]);$i++)
{
    $value[$i] = $_POST["res"][$i];
    $iCount = count($value);

    $data =array_merge($value);

    $res = array_unique( $data );

//print_r($res); 
//echo $res[$i]."<br>";

}
}

if ( isset( $_POST[facilities] ) ) //รับค่าสิ่งอวยความสะดวก
  {
   for($i=0;$i<count($_POST["facilities"]);$i++)
{
    $fac[$i] = $_POST["facilities"][$i];
    $iCount2 = count($fac);


//echo $fac[$i]."<br>";
}
}e

?>


<?php

    $objConnect = mysql_connect("localhost","root","12345678") or die("Error Connect to Database");
    $objDB = mysql_select_db("knn");
    // Search By 
    $tempdrop="DELETE FROM temp";//ลบข้อมูลtemp
    mysql_query($tempdrop);
    $strSQL = "SELECT * FROM restaurant WHERE category LIKE '%";
    $temp="INSERT INTO temp (id_temp,name_temp,category_temp,address_temp,phone_temp,facilities_temp,time_temp,images_temp,lat_temp,long_temp,view_temp) 
               SELECT * from restaurant WHERE category like '%";?>

 <div><? echo "<b>คุณค้นหาประเภทอาหารคำว่า: </b>"; ?></div>
<?
    for ($i = 0 ; $i<$iCount; $i++) {
        if ($res[$i]=="") {
            continue;
        }
        if ($i == 0){
            $strSQL = $strSQL.$res[$i]."%'"; 
            $temp= $temp.$res[$i]."%'";
        }
        else{
            $strSQL = $strSQL." OR category LIKE '%".$res[$i]."%'";
            $temp= $temp." OR category LIKE '%".$res[$i]."%'";
          }
     
     echo $res[$i].","; 

    }
    ?>

     <div> <?echo "<b>คุณค้นหาสิ่งอำนวยความสะดวกคำว่า: </b>"."<br>";?></div>
      <?
      for ($i = 0 ; $i<$iCount2; $i++) {
        if ($fac[$i]=="") {
            continue;
        }
        if ($i == 0){
            
            $strSQL = $strSQL." OR facilities LIKE '%".$fac[$i]."%'";
            $temp= $temp." OR facilities LIKE '%".$fac[$i]."%'";  
        }
        else{
            $strSQL = $strSQL." OR facilities LIKE '%".$fac[$i]."%'"; 
            $temp= $temp." OR facilities LIKE '%".$fac[$i]."%'";
        }  
         echo $fac[$i].",";   
        }
        

//echo $strSQL."<br>";
   
    $objQuery = mysql_query($strSQL);
    $querytemp=mysql_query($temp);
           
    ?>
   <div class="container">

    <table width="100%" border="1" class="table table-hover" >
      <tr>
        
        <th > <div align="center">ชื่อร้านอาหาร</div></th>
        <th > <div align="center">รายการที่ค้นหาพบ</div></th>
        <th > <div align="center">สิ่งอำนวยความสะดวก</div></th>

      </tr>
      <?php     while ($objResult = mysql_fetch_array($objQuery)) { //ส่วนแสดงผล
            $face = $objResult["facilities"];
            $color = $objResult["category"];
             $dataid=$objResult["id"];
        ?>
      

       <?php
            $keySearch = $res;//สีประเภทอาหาร
            $b = array();
                foreach($keySearch as $val){
                    $b[$val] = '<font color=#09ba32><b>'.$val.'</b></font>';
                }
             ?>
             <?php
            $keyfac = $fac;//สีสิ่งอำนวยความสะดวก
            $a = array();
                foreach($keyfac as $valfac){
                    $a[$valfac] = '<font color=#09ba32><b>'.$valfac.'</b></font>';
                }
            
             ?>
        <tr>
        <td><a href="show.php?id=<?php echo $objResult["id"];?>"><?php echo $objResult["nameres"];?></a></td> 
        <td><?php echo str_replace(array_keys($b), $b,$color); ?></td>
        <td><?php echo str_replace(array_keys($a), $a,$face); ?></div></td>

      </tr>

        <?php
        }
        ?>
    </table>
    </div>


Jame Panuwat Suksamran 182.53.213.xxx 29-01-2017 18:17
 ความคิดเห็นที่ 2
เอาตัวอย่างนี้ไปทดสอบรัน แล้วดูการทำงานเป็นแนวทาง

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<pre>
<?php print_r($_POST); ?>
</pre>
<form action="" method="post" >
Data 1: 
<?php for($i=1;$i<5;$i++){?>
<input name="data1[]" type="checkbox" id="data1[]" value="datavalue <?=$i?>">
 <?php }?>
 <br>
 Data 2:
<?php for($i=1;$i<5;$i++){?>
 <input name="data2[]" type="checkbox" id="data1[]" value="data2value <?=$i?>">
 <?php }?>
 <br>
 <input type="submit" value="Submit" />
  <br />
</form>
<pre>
<?php
$sql_more = "";
if(isset($_POST['data1'])){
	foreach($_POST['data1'] as $k=>$v){
		if($v!=""){
			$sql_more .= " OR category LIKE '%".$v."%' ";
		}
	}
}
if(isset($_POST['data2'])){
	foreach($_POST['data2'] as $k=>$v){
		if($v!=""){
			$sql_more .= " OR facilities LIKE '%".$v."%' ";
		}
	}
}
$sql = "
SELECT * FROM restaurant WHERE 1 $sql_more 
";
echo $sql;
?>
</pre>
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script>

 
</script>
</body>
</html>


ninenik 1.47.106.xxx 29-01-2017






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ