显示搜索结果的$ result

时间:2013-10-24 07:29:57

标签: php mysql

我最近完成了我的搜索引擎,但现在我遇到了新的挑战。

以下代码我使用它来读取数据库中的调用流表中的值,并将它们显示在一个表格中,让您知道该呼叫是否被回答。

  if(isset($res))
        {
            //creating table
            echo '<table style="width:1500px; cell-padding:4px; cell-spacing:0; margin:auto;">';       
            echo'<th>Time</th><th>Answered Y/N</th></th><th>Naam</th><th>Caller ID</th>'; 

           while($result = mysql_fetch_assoc($res))
            {
              echo '<tr>';

              echo '<td>'.$result['statusCalling'].'</td>';
              if ($result['statusAnswered'] =="NULL"||$result['statusAnswered'] =="Null" || $result['statusAnswered'] =="null" || $result['statusAnswered'] =="")
      {
      echo "<td>Not Answered!</td>";
      }
    else
      {
      echo "<td>Answered!</td>";
      }
              echo '<td>'.$result['calleridname'].'</td>'.'<td>'.$result['calleridnum'].'</td>' ;
              echo '</tr>';
            }
            echo '</table>';
        }

我现在需要在搜索引擎结果中显示这些结果! 我试过这个,但我不工作!不知道怎么回事!请帮忙!

$output = '';
//collect
if(isset($_POST['asd']))  {
 $searchq = $_POST['search'];
 $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
  $query = mysql_query('SELECT * FROM callflow WHERE statusCalling LIKE "%'.$searchq.'%" OR calleridname LIKE "%'.$searchq.'%" OR calleridnum LIKE "%'.$searchq.'%" OR $results LIKE "%'.$searchq'%"');
  $count = mysql_num_rows($query);
 if($count == 0) {
  $output = 'There was no search results!';
 }else{
  while($row = mysql_fetch_array($query)) {
   $statusCalling = $row['statusCalling'];
   $calleridname = $row['calleridname'];
   $calleridnum = $row['calleridnum'];
   $results = $row['statusAnswered'];
   $id = $row['ID'];
   $output .= '<div>'.$statusCalling.' '.$calleridname.' '.$calleridnum.' '.$results.'</div>';
  }
  }
}

我知道mysql已被弃用,我正在学习编程,我想如果我不知道mysql我不能学习pdo因为我不明白什么是什么。请帮忙!

1 个答案:

答案 0 :(得分:0)

我已经找到了答案,我在这里发布,所以其他人在研究类似的东西时可以看到解决这个问题的方法。

<?php
mysql_connect("localhost","root","") or die("Could not connect");
mysql_select_db("voizxl_wachtrij") or die("Could not find Database");

$output = '';
//collect
if(isset($_POST['asd']))  {
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
  $query = mysql_query('SELECT * FROM callflow WHERE statusCalling LIKE "%'.$searchq.'%" OR calleridname LIKE "%'.$searchq.'%" OR calleridnum LIKE "%'.$searchq.'%"');
  $count = mysql_num_rows($query);
    if($count == 0) {
        $output = 'There was no search results!';
    }else{
        while($row = mysql_fetch_array($query)) {
            $statusCalling = $row['statusCalling'];
            $calleridname = $row['calleridname'];
            $calleridnum = $row['calleridnum'];
            $id = $row['ID'];
            $output[] = $row;
        }
        }
}   
?> 

<?php foreach($output as $o){;
                 if($o['statusAnswered']){


                 echo $o['statusCalling'].' Answered: '.$o['calleridname'].' '.$o['statusAnswered'].' '.$o['calleridnum'].'<br />';

                 }else{
                 echo $o['statusCalling'].' Not Answered: '.$o['calleridname'].' '.$o['calleridnum'].'<br/>';
                 }

              }?>

               <br/><br/><br/>
    <?php

干杯