2011-08-15 17 views
0

検索フォームを使用して検索クエリの後に結果が表示されないというメッセージが表示されない場合があります。下の私のコード。誰かが助けてくれますか?検索の前に結果と明確なクエリーストリングのためのMysql検索メッセージ?

たとえば、私が3ページ目で検索してフォームを検索したときに検索が実行されると、クエリ文字列をクリアすることもできますが、すでに設定されているクエリ文字列のためにページ3にあります。希望は意味をなさない。

function supportquery($viewstate) { 

$display = 6;// number of results per page 

     if (isset($_GET['np'])) { 
    $num_pages = $_GET['np']; 
} else { 

    $where = "1"; // default 
    switch ($viewstate) { 
     case "open": $where = "status='Open'"; break; 
     case "pending": $where = "status LIKE 'Pending%'"; break; 
     case "closed": $where = "status='Closed'"; break; 
    } 

    $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, 
     message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE $where ORDER BY ticket_number DESC"; 
     $search = "%" . $_POST["search"] . "%"; 
    if ($_POST["search"]) { $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE ticket_number LIKE '$search' OR email LIKE '$search' ORDER BY ticket_number DESC"; 

} 

    $query_result = mysql_query ($query); 
    $num_records = @mysql_num_rows ($query_result); 
    if ($num_records > $display) { 
     $num_pages = ceil ($num_records/$display); 
    } else { 
     $num_pages = 1; 
    } 
} 



if (isset($_GET['startoftable'])) { 
    $start = $_GET['startoftable']; 
} else { 
    $start = 0;// start of results from row 0 in table 

} 

    $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev ORDER BY ticket_number DESC LIMIT $start, $display"; 
    if ($viewstate=='open') { 

     $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE status='Open'ORDER BY ticket_number DESC LIMIT $start, $display"; 
     } 
      elseif ($viewstate=='pending') { 
     $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE status LIKE 'Pending%' ORDER BY ticket_number DESC LIMIT $start, $display"; 
     } 
     elseif ($viewstate=='closed') { 
     $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE status='Closed' ORDER BY ticket_number DESC LIMIT $start, $display";} 


    if ($_POST["search"]) { 
     $query = "SELECT ticket_number, first_name, surname, email, product, retailer, DATE_FORMAT(dop, '%d %M %Y') AS dop, message, address, DATE_FORMAT(created, '%d %M %Y %r') AS created, status FROM support_dev WHERE ticket_number LIKE '$search' OR email LIKE '$search' ORDER BY ticket_number DESC LIMIT $start, $display"; 


     } 

     $result = @mysql_query ($query); 
     $num = mysql_num_rows ($result); 

if ($num > 0) { 

    if ($num_pages > 1) { 
     echo '<div class="pagination"><p>'; 
     $current_page = ($start/$display) + 1; 

     if ($current_page != 1) { 
      echo '<a href="?page_id=1072&amp;startoftable=' . (0) . '&np=' . $num_pages . '&viewstate=' . $viewstate .'">First</a> '; 
      echo '<a href="?page_id=1072&amp;startoftable=' . ($start - $display) . '&np=' . $num_pages . '&viewstate=' . $viewstate . '"><</a> '; 
     } 

    // range of num links to show 
$range = 4; 

// loop to show links to range of pages around current page 
for ($i = ($current_page - $range); $i < (($current_page + $range) + 1); $i++) { 
    // if it's a valid page number... 
    if (($i > 0) && ($i <= $num_pages)) { 
     // if we're on current page... 
     if ($i == $current_page) { 
     // 'highlight' it but don't make a link 
     echo " [<b>$i</b>] "; 
     // if not current page... 
     } else { 
     // make it a link 
    echo ' <a href="?page_id=1072&amp;startoftable=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&viewstate=' . $viewstate .'">' .$i .'</a> '; 

     }}} 

     if ($current_page != $num_pages) { 

      echo '<a href="?page_id=1072&amp;startoftable=' . ($start + $display) . '&np=' . $num_pages . '&viewstate=' . $viewstate .'">></a> '; 
      echo '<a href="?page_id=1072&amp;startoftable=' . ($display * $num_pages-$display) . '&np=' . $num_pages . '&viewstate=' . $viewstate .'">Last</a> '; 
     } 

     echo '</p></div> '; 

    } 

     if ($result = mysql_query ($query)) { 
     echo ' 
    <div id="supviewwrapperheader"> 
    <div id="supviewticket"><p>Ticket</p></div> 
    <div id="supviewfirst"><p>First Name</p></div> 
    <div id="supviewlast"><p>Last Name</p></div> 
    <div id="supviewemail"><p>Email</p></div> 
    <div id="supviewproduct"><p>Product</p></div> 
    <div id="supviewretailer"><p>Retailer</p></div> 
    <div id="supviewdop"><p>D.O.P.</p></div> 
    <div id="supviewmessage"><p>Message</p></div> 
    <div id="supviewaddress"><p>Address</p></div> 
    <div id="supviewcreated"><p>Date created</p></div> 
    <div id="supviewstatus"><p>Status</p></div> 
    <div id="supviewbuttons"><p></p></div> 
    </div> 
    '; 

    while ($row = mysql_fetch_array($result, MYSQL_NUM)) { 
     echo " 
     <div id=\"supviewwrapper\" class=\"".($row[10])."\"> 
     <div id=\"supviewticket\"><p><a name=\"a".$row[0]."\"></a>$row[0]</p></div> 
     <div id=\"supviewfirst\"><p>$row[1]</p></div> 
     <div id=\"supviewlast\"><p>$row[2]</p></div> 
     <div id=\"supviewemail\"><p>$row[3]</p></div> 
     <div id=\"supviewproduct\"><p>$row[4]</p></div> 
     <div id=\"supviewretailer\"><p>$row[5]</p></div> 
     <div id=\"supviewdop\"><p>$row[6]</p></div> 
     <div id=\"supviewmessage\"><p>$row[7]</p></div> 
     <div id=\"supviewaddress\"><p>$row[8]</p></div> 
     <div id=\"supviewcreated\"><p>$row[9]</p></div> 
     <div id=\"supviewstatus\"><p>$row[10]</p></div> 
     <div id=\"supviewbuttons\"><p><form method=\"post\" action=\"".htmlentities($_SERVER['REQUEST_URL'])."#a".$row[0]."\"><input type=\"hidden\" name=\"close_row\" value=\"".($row[0])."\" /><input type=\"hidden\" name=\"viewstate\" value=\"".$viewstate."\" /><INPUT TYPE=\"submit\" name=\"open\" VALUE=\"\" class=\"submit_open\"><br /><INPUT TYPE=\"submit\" name=\"pending\" VALUE=\"\" class=\"submit_pending\"><br /><INPUT TYPE=\"submit\" name=\"pending_ami\" VALUE=\"\" class=\"submit_pendingami\"><br /><INPUT TYPE=\"submit\" name=\"pending_arp\" VALUE=\"\" class=\"submit_pendingarp\"><br /><INPUT TYPE=\"submit\" name=\"close\" VALUE=\"\" class=\"submit_closed\"></form></p></div></div>"; 



    } 


    } 

    mysql_free_result ($result); 

    } 

答えて

1

文字列内の文字列と一致させるには、LIKE "%{$search}%"を使用する必要があります。

+0

こんにちは、チップのおかげで、まだ私の他の問題を助けていない。 – Lee

関連する問題