First up soory for the long messge but I'm totally stuck, I've been stuck 
for the past 3 days. I'm trying to display the results of a search, The 
code I've written so far displays the first five results and the links to 
pages for the rest, how do I display only the rows that I want.

The code I've written so far>>>>

<<<<--------------------------->>>>>
<?session_start($clothes);?>

<html>

<body>

<h3> Search results...</h3>

<?

//$p = getenv("QUERY_STRING");

echo $p;

echo $search;


@ $db = mysql_pconnect("localhost", "root", "odlaner");

if (!$db)
{
 echo "Error: Could not connect to the database. Please try again later.";
 exit;
}

echo "<br>";

$searchwords = split(" ", $search);

/*
foreach($searchwords as $line)
        {
        $sql_1.= "description like '%$line%' or ";
        $sql_2.= " name like '%$line%' or";
        $sql_3.= " type like '%$line%' or";
        }
$rest = substr($sql_3, 0, strlen($sql_3)-3);

$partsql.= $sql_1 . $sql_2 . $sql_3 ;

$command = substr($partsql, 0, strlen($partsql)-3);
$search = $command;
*/

if (empty($search))
{
echo "You did not enter a search string, please go back and try again";
quit;
}
echo "<br>";

mysql_select_db("clothes");

$list = "select * from products WHERE MATCH ( type,name,description ) 
AGAINST ('$search')";

$results = mysql_query($list);

$num_results = mysql_num_rows($results);

$num_temp = ceil($num_results / 5) ;
echo "<br>";
$num_pages = $num_temp + 1;
echo "$num_pages pages";
echo "<br>";

$row = mysql_fetch_array($results);

$i= 0;
$m= 5;

        if ($p != 0 )
        {
        $i = 5 * $p;
        $m = ($m * $p) + 5;
        }
if ($num_results)
{
for ( $i=$i;  $i<$m; $i++)
{
$row = mysql_fetch_array($results);

               echo "<p><b>Type:</b>";
               echo  $row["type"];
               echo "<b> Name:</b>";
               echo  $row["name"];
               echo "<b> Price:</b>";
               echo  $row["price"];
               echo "<br>";
               echo "<b> Description:</b>";
               echo  $row["description"];
         if ($row["image1"])
        {
echo "<br>";
echo "<b> Image 1: </b>";
?>
<img src="http://cirkit.com/images/<?echo 
htmlspecialchars(stripslashes($row["image1"]));?> ">
<?
         }
         if ($row["image2"])
         {
echo  "<br>";
echo "<b> Image 2: </b>";
?>
<img src="http://cirkit.com/images/<?echo 
htmlspecialchars(stripslashes($row["image2"]));?> ">
<?
        }
        if ($row["image3"])
        {
echo "<br>";
echo "<b> Image 3: </b>";
?>
<img src="http://cirkit.com/images/<?echo 
htmlspecialchars(stripslashes($row["image3"]));?> ">
<?
        }
echo "</p>";
}
}
     //diplay no result found if search unsucessful
     else
     {
     echo "No results found. Please try another search phrase.";
     }
                                   // dislpays the links @ the bottom of 
the page
                                   echo "<br>";
                                   echo "<br>";
                                   for ($p=0; $p<$num_pages; $p++)
                                           {
                                           $id = "p=$p&search=$search";
                                           ?>
                                           <a href="search.php?<? echo $id; 
?>
                                           ">
                                           <? echo $p; ?>
                                           </a>
                                           <?
                                           }


?>
<br>
<a href="home.php">HOME</a>


</body>

</html>

<<<<<<<----------------------------------->>>>>>

Can anyone help me please, I'm new at this only been programming for 3 
weeks.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to