0

please do not hate because i have searched far and wide for a cure to my problem here. I am using xampp to run this php code in question. The problem is that the search function works perfectly but for some reason my if statements varying what order it is sorted by do not. All help is appreciated. All love no hate. Thanks.

    <html>
<head>  

<title>SeedBase</title>
<link rel="stylesheet" type="text/css" href="CSSstyle.css">

</head>

<body>
<h1 class="logo">SeedBase</h1>

<ul div class="navbar">
    <li><a href="HTMLhome.HTML">Home     |</a></li>
    <li><a href="PHPseeds.php">Seeds     |</a></li>
    <li><a href="HTMLcontact.html">Contact</a></li>
</ul>


<div class="search">
<form method="POST" action="PHPseeds.php">
    <p>Search SeedBase:<input type="text" name="searchbox" value="seed"></p>
        <p><select name="selector">
        <optgroup label = "Sort By">
            <option value="def" selected>Defult</option>
            <option value="asc" >Quantity Asc</option>
            <option value="desc">Quantity Desc</option>
        </optgroup>
    </select></p>

        <p><input type="submit" name="button" value="GO"></p>
</form>
</div>





<?php
echo "<phpcss>";
include 'db.inc.php';

$row = 0;
$find = $_POST['searchbox'];
$choice = $_POST['selector'];
$output = "";

    if ($find != '') {
        if ($choice="def"){
        $sql =  "SELECT * FROM seeds WHERE  name LIKE '%$find%' OR description LIKE  '%$find%' "; 
        }
        else if ($choice="asc"){
        $sql =  "SELECT * FROM seeds WHERE  name LIKE '%$find%' OR description LIKE  '%$find%' ORDER BY quantity ASC "; 
        }
        else if ($choice="desc"){
        $sql =  "SELECT * FROM seeds WHERE  name LIKE '%$find%' OR description LIKE  '%$find%' ORDER BY quantity DESC "; 
        }
    }

    if ($find == ''){
        if ($choice="Defult"){
        $sql =  "SELECT * FROM seeds "; 
        }
        else if ($choice="asc"){
        $sql =  "SELECT * FROM seeds WHERE  name LIKE '%$find%' OR description LIKE  '%$find%' ORDER BY quantity ASC "; 
        }
        else if ($choice="desc"){
        $sql =  "SELECT * FROM seeds WHERE  name LIKE '%$find%' OR description LIKE  '%$find%' ORDER BY quantity DESC "; 
        }

    }
$result = $pdo->query($sql);
?>



<div class="DBpic">
<?php
    echo "<table>";
foreach ($result as $row)
{
    $seed = $row['name'];
    $description = $row['description'];
    $quantity = $row['quantity'];
    $image = $row['image'];
    $output ="<tr><tr> $seed <tr> $quantity cases" ;

    echo "<table>";
    echo  '<br><img src="data:image/jpeg;base64,' . base64_encode( $row['image'] ) . '" /><br>'. $output;
    echo "</table>";

    }
    echo "</table>";



?>
</div>




<?php
if ($row == 0)
{
echo "nothing could be found for that search term";
}
echo "</phpcss>";
?>


</body>
</html>
Nigel Ren
  • 51,875
  • 11
  • 34
  • 49
guyman123
  • 1
  • 1

1 Answers1

0

In second If Condition you have to use !=

 if ($find != '')
Jay Shankar Gupta
  • 5,707
  • 1
  • 7
  • 26