2014-10-20 43 views
-1

我試圖獲得以下查詢:
如果存在A的值和B的值,或者如果存在A的值或者存在B的值 - - >做一些在一個if循環中存在多個isset查詢

if((isset($_POST['A'], $_POST['B'])) OR !empty($_POST['B']) OR !empty($_POST['A'])) 
    { 
     echo "there is something:" . $_POST['B'] . ", " . $_POST['A']; 
    } 
    else 
    { 
     echo "its empty<br />"; 
    } 

當領域之一是值正常工作,但是當我們有空這兩個領域依然是明顯的東西存在。

葡萄酒可能與自動完成?

$checkVIN1 = mysql_query("SELECT vhl_vin FROM vhldescription"); 
$num_rows = mysql_num_rows($checkVIN1); 
$i = 0; 
echo "<script>$(function() {var availableTags = ["; 
while($checkVIN2 = mysql_fetch_array($checkVIN1, MYSQL_ASSOC)) { $i++; echo "\"" . <br />$checkVIN2['vhl_vin'] . "\","; 
    if ($i == ($num_rows)) { echo "\"" . $checkVIN2['vhl_vin'] . "\""; } } 
echo "];$(\"#tags\").autocomplete({source: availableTags});});</script>"; 
<input id="tags" name="A" class="le-input"> 
+0

['mysql_'功能已被棄用(http://bit.ly/phpmsql) – Mooseman 2014-10-20 16:27:35

+0

把一個ELSEIF條件收緊你的支票。 – unixmiah 2014-10-20 16:30:32

回答

0

這個怎麼樣?

<?php 
$a; 
$b; 


if((isset($a) or isset($b)) and !(empty($a) or empty($b))){ 
    echo "do something";  
}else{ 
    echo "do nothing"; 
} 
0

試圖改變你的代碼如下:

$postVars = array('A', 'B'); 
$things = array(); 
foreach($postVars as $postVar) { 
    if(isset($_POST[$postVar]) && !empty($_POST[$postVar])) 
    { 
     $things []= $_POST[$postVar]; 
    } 
} 

if(empty($things)) { 
    echo "it's empty<br />"; 
} else { 
    echo "there is something: " 
     . join(', ', array_map(function($str) { 
            return htmlspecialchars($str, ENT_NOQUOTES, 'UTF-8');   
           }, 
           $things)) . '.'; 
}