Reorder of Search Results

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Reorder of Search Results

Post by Stelios »

Hi again!!! :D

I would like to be able to reorder the search results according to specific fields. How is this possible? Is there any tutorials about this matter?

Thanks a lot again! :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have an example we can look at?
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

Well not a running web site but some code....

This is it...:

Code: Select all

<?php
$page_title = 'Search Results';
include_once('header.html');
include_once('mysql_connect.php');


$searchtype=$HTTP_POST_VARS&#1111;'searchtype'];
$searchterm=$HTTP_POST_VARS&#1111;'searchterm'];

$searchterm= trim($searchterm);

if (!isset($_SESSION&#1111;'first_name'])) &#123;
	
	header ("Location:  http://" . $_SERVER&#1111;'HTTP_HOST'] . dirname($_SERVER&#1111;'PHP_SELF']) . "/login.php");
	ob_end_clean(); // Delete the buffer.
	exit(); // Quit the script.
&#125;

  if (!$searchtype || !$searchterm)
  &#123;
     echo 'You have not entered search details.  Please go back and try again.';
     include('footer.html');
	exit;
  &#125;
  
  $searchtype = addslashes($searchtype);
  $searchterm = addslashes($searchterm);

$query = "SELECT * FROM uploads,images,artists WHERE ".$searchtype." like '%".$searchterm."%' AND uploads.song_id = images.image_id ORDER BY upload_date DESC";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);


echo "<fieldset><h4><legend><font face="Palatino Linotype, Verdana, Arial"><strong>Search Results for <font color="#FF0000"> '$searchterm'</strong></font></font></legend></h4>";
echo '<table border="0" width="100%" cellspacing="2" cellpadding="2" align="center">
<tr bgcolor="#0066FF" bordercolor="#000000">
      <td align="center" width="20%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Image</b></font></td>
	<td align="center" width="20%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Song Title</b></font></td>
	<td align="center" width="20%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Artist/Group</b></font></td>
	<td align="center" width="15%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Genre</b></font></td>
	<td align="center" width="10%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Duration</b></font></td>
	<td align="center" width="15%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Rating</b></font></td>
	
      </tr></td>';


while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) &#123;

	// Display each record.
	echo "	<tr>
		<td align="center" bgcolor="#FFFFCC"><a href=../fyp/imageuploads/&#123;$row&#1111;'image_name']&#125;><img src="../fyp/imageuploads/&#123;$row&#1111;'image_name']&#125;" alt="&#123;$row&#1111;'image_name']&#125;" height=80 width=80/></a> </td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'song_title']) . "</td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'artist_name']) . "</td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'type']) . "</td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'duration']) . "</td>
		<td align="center" bgcolor="#FFFFCC"><img src="../fyp/&#123;$row&#1111;'rating']&#125;" alt="&#123;$row&#1111;'rating']&#125;" /> </td>
		 

</td>
			</tr>\n";

&#125;

echo '</table></fieldset>'; // Close the table.
	

include_once('footer.html');
?>
The search results are set to order the table by upload_date. My question is whether I can enable users resorting the results on the fly for example by rating...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

so something like this:

viewtopic.php?t=25082
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

Well I have been looking at this thing for hours and I cant understand :cry: ...Is there any tutorial I can look at to find out how to do it?

Thanks!
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

Ok I've done this but it comes back to say that its trying to do a new search in which I have not added any search details...Can anybody help please????

Code: Select all

<?php
$page_title = 'Search Results';
include_once('header.html');
include_once('mysql_connect.php');


$searchtype=$HTTP_POST_VARS&#1111;'searchtype'];
$searchterm=$HTTP_POST_VARS&#1111;'searchterm'];

$searchterm= trim($searchterm);

if (!isset($_SESSION&#1111;'first_name'])) &#123;
	
	header ("Location:  http://" . $_SERVER&#1111;'HTTP_HOST'] . dirname($_SERVER&#1111;'PHP_SELF']) . "/login.php");
	ob_end_clean(); // Delete the buffer.
	exit(); // Quit the script.
&#125;

  if (!$searchtype || !$searchterm)
  &#123;
     echo 'You have not entered search details.  Please go back and try again.';
     include('footer.html');
	exit;
  &#125;
  
  $searchtype = addslashes($searchtype);
  $searchterm = addslashes($searchterm);

$query = "SELECT * FROM uploads,images,artists WHERE ".$searchtype." like '%".$searchterm."%' AND uploads.song_id = images.image_id ORDER BY '&#123;$_GET&#1111;'newsort']&#125;' ASC";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);


echo "<fieldset><h4><legend><font face="Palatino Linotype, Verdana, Arial"><strong>Search Results for <font color="#FF0000"> '$searchterm'</strong></font></font></legend></h4>";
echo '<table border="0" width="100%" cellspacing="2" cellpadding="2" align="center">
<tr bgcolor="#0066FF" bordercolor="#000000">
      <td align="center" width="20%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Image</b></font></td>
	<td align="center" width="20%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><a href="'. $_SERVER&#1111;'PHP_SELF'] .'?newsort=song_title"><b>Song Title</b></a></font></td>
	<td align="center" width="20%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Artist/Group</b></font></td>
	<td align="center" width="15%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Genre</b></font></td>
	<td align="center" width="10%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Duration</b></font></td>
	<td align="center" width="15%"><font color="#FFFFFF" face="Palatino Linotype, Verdana, Arial"><b>Rating</b></font></td>
	
      </tr></td>';


while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) &#123;

	// Display each record.
	echo "	<tr>
		<td align="center" bgcolor="#FFFFCC"><a href=../fyp/imageuploads/&#123;$row&#1111;'image_name']&#125;><img src="../fyp/imageuploads/&#123;$row&#1111;'image_name']&#125;" alt="&#123;$row&#1111;'image_name']&#125;" height=80 width=80/></a> </td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'song_title']) . "</td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'artist_name']) . "</td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'type']) . "</td>
		<td align="center" bgcolor="#FFFFCC">" . stripslashes($row&#1111;'duration']) . "</td>
		<td align="center" bgcolor="#FFFFCC"><img src="../fyp/&#123;$row&#1111;'rating']&#125;" alt="&#123;$row&#1111;'rating']&#125;" /> </td>
		 

</td>
			</tr>\n";

&#125;

echo '</table></fieldset>'; // Close the table.
	

include_once('footer.html');
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code doesn't pass the search parameters searched for initially. Thus losing that information.
User avatar
Stelios
Forum Commoner
Posts: 71
Joined: Fri Feb 06, 2004 6:25 am
Location: Surrey/UK

Post by Stelios »

Would my problem be solved if I store the $result in another variable?
Post Reply