1
我想實現一個快速搜索欄來搜索由SQL數據庫填充的表。搜索不會搜索表,但會生成SQL語句並搜索數據庫。我需要使用PHP來實現一個搜索功能,該功能將使用標誌來停止搜索。這是到目前爲止我的代碼:帶標誌的搜索功能
//THIS CODE WILL EXECUTE WHEN THE SEARCH BUTTON IS PRESSED
if($_REQUEST['btnsearch']){
if(isset($_POST['quicksearch']) and !empty($quicksearch)){
$sql = "SELECT column_name FROM information_schema.columns WHERE table_name ='alerts_table'
AND column_name IN('name', 'year','make','model','alert','date')";
$retvalues = mysqli_query($conn, $sql);
$data = array();
//LOOP POPULATES THE ARRAY WITH THE CURRENT COLUMN NAMES.
for($counter = 0; $counter <= $row=mysqli_fetch_array($retvalues, MYSQL_ASSOC); $counter++){
$string = $row["column_name"];
$data[$counter] = $string;
}
$length = count($data);
$flag = 1;
while($flag == 1){
for($x = 0; $x <= $length - 1; $x++){
$sql3="SELECT * FROM alerts_table WHERE $data[$x] = $quicksearch";
$retvalues2=mysqli_query($conn, $sql3);
if(!empty($retvalues2))
{
//POPULATE THE TABLE WITH RESULTS HERE !!!!!!!!!
$flag = -1; ///HOW CAN I BREAK THE LOOP???
}
}
}
}else{
你能澄清你具體問的是什麼嗎? – sdsmith
是的,我道歉,我需要知道如何找到匹配時使用標誌打破循環。例如,如果查詢返回match..stop循環 – vhdz04
使用'break'語句打破循環。這應該在任何PHP教程中解釋。 – Barmar