jeudi 24 août 2017

Search filtering from database likr facebook **find friends** page, PHP

How to create a search filter like the find friends page on facebook

How to create a search filter like the find friends page on facebook. I have 3 column bodybuild, ethnictype, skincolor in table accounts. I already created the view for my page and the checkboxes in it doesn't filtering the values now. It displays all the values that i checked without filtering. I just need , if bodybuild=1 AND ethnictype=2 AND skincolor=1, I want to display the name of the user which has this values in his row.

heres the code which i use now,

here is the new updated code,

if(isset($_REQUEST['search'])){
$pro_price = $_REQUEST['pro_price'];
$pro_code = $_REQUEST['pro_code'];
$hsn_code = $_REQUEST['hsn_code'];
foreach ($_REQUEST['pro_price'] as $pro_price) {
    $statearray[] = mysql_real_escape_string($pro_price);
}
foreach ($_REQUEST['pro_code'] as $pro_code) {
    $codesarray[] = mysql_real_escape_string($pro_code);
}
foreach ($_REQUEST['hsn_code'] as $hsn_code) {
    $hsnarray[] = mysql_real_escape_string($hsn_code);
}
$states = implode ("','", $statearray);
$codes = implode ("','", $codesarray);
$hsn = implode ("','", $hsnarray);
$sql = "SELECT * FROM addproduct WHERE pro_price IN ('$states') OR pro_code IN ('$codes') OR hsn_code IN ('$hsn')";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) == 0)
{
    echo "Sorry, but we can not find an entry to match your query...<br><br>";
}
else
{
    echo "<table border='1' width='900' class='srchrslt'>
    <tr class='head'>
    <td>pro_name</td>
    <td>pro_brand</td>
    <td>hsn_code</td>
    <td>pro_price</td>
    <td>pro_code</td>
    </tr>";
    while($row = mysql_fetch_assoc( $result ))
    {              
        echo "<tr>";
        echo "<td>" . $row['pro_name'] . " </td>";
        echo "<td>" . $row['pro_brand'] . " </td>";
        echo "<td>" . $row['hsn_code'] . " </td>";
        echo "<td>" . $row['pro_price'] . " </td>";
        echo "<td>" . $row['pro_code'] . " </td>";
        echo "</tr>";
    }
    echo "</table>";
}}




Aucun commentaire:

Enregistrer un commentaire