Jump to content

[SOLVED] Problem with search code..


MDanz

Recommended Posts

where did i go wrong.

 

 

when i type the letter B alone in the search bar they show both images, when its only supposed to show when you type in the full word 'Basketball'.  Also when i type nothing in the bar it displays all three images in my database, when it should say "nothing is found".

 

 

<?php

//get data

 

 

 

 

$button = $_GET['submit'];

$search = $_GET['search'];

 

if

 

(!$button)

echo "You didn't submit a keyword";

 

else

{

if(!isset($search) ||  strlen($search)<=2)

echo "search term too short";

else

{

echo "<br><br><font color=white>you searched for <b>$search</b></font><hr size='1'>";

}

mysql_connect("localhost", "Master", "password");

mysql_select_db("ustackc1_Login");

 

 

//explode our search term

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each)

{

//construct query

$x++;

if($x==1)

        $construct .= "keywords LIKE '%$search_each%'";

        else

        $construct .= "OR keywords LIKE '%$search_each%'";

}

 

                  //echo out $construct

$construct = "SELECT * FROM Upload WHERE $construct";

}              $run = mysql_query($construct);

                $foundnum =  mysql_num_rows($run);

 

if  ($foundnum==0)

echo "No Stacks Found";

else

{

    echo "$foundnum Stacks Found!<p>";

  echo '<table>';

 

    while ($runrows = mysql_fetch_assoc($run))

    {

              //get data

        $name = $runrows['name'];

        $image = $runrows['image'];

        $hyperlink = $runrows['hyperlink'];

        $currency = $runrows['currency'];

        $info = $runrows['info'];

        $type = $runrows['type'];

 

 

 

        echo '<tr><td>';

switch ($type) {

    case 'I':

        echo '<img src="http://www.u-stack.com/Image.jpg">';

        break;

    case 'M':

        echo '<img src="http://www.u-stack.com/Music.jpg">';

        break;

    case 'F':

        echo '<img src="http://www.u-stack.com/File.jpg">';

        break;

    case 'V':

        echo '<img src="http://www.u-stack.com/Video.jpg">';

        break;

 

 

 

}  echo '</td></tr>';

 

 

 

    }

   

   

    echo '</table>';

}

 

?>

 

 

 

it seems if i type in any letter within 'Basketball' it displays the results, when i want the full keyword to be typed in to display the result.

Link to comment
https://forums.phpfreaks.com/topic/169048-solved-problem-with-search-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.