Page 1 of 1
Reorder of Search Results
Posted: Tue Jan 18, 2005 1:35 pm
by Stelios
Hi again!!!
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!

Posted: Tue Jan 18, 2005 2:04 pm
by feyd
you have an example we can look at?
Posted: Tue Jan 18, 2005 2:11 pm
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ї'searchtype'];
$searchterm=$HTTP_POST_VARSї'searchterm'];
$searchterm= trim($searchterm);
if (!isset($_SESSIONї'first_name'])) {
header ("Location: http://" . $_SERVERї'HTTP_HOST'] . dirname($_SERVERї'PHP_SELF']) . "/login.php");
ob_end_clean(); // Delete the buffer.
exit(); // Quit the script.
}
if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
include('footer.html');
exit;
}
$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)) {
// Display each record.
echo " <tr>
<td align="center" bgcolor="#FFFFCC"><a href=../fyp/imageuploads/{$rowї'image_name']}><img src="../fyp/imageuploads/{$rowї'image_name']}" alt="{$rowї'image_name']}" height=80 width=80/></a> </td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'song_title']) . "</td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'artist_name']) . "</td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'type']) . "</td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'duration']) . "</td>
<td align="center" bgcolor="#FFFFCC"><img src="../fyp/{$rowї'rating']}" alt="{$rowї'rating']}" /> </td>
</td>
</tr>\n";
}
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...
Posted: Tue Jan 18, 2005 2:26 pm
by feyd
so something like this:
viewtopic.php?t=25082
Posted: Wed Jan 19, 2005 7:59 am
by Stelios
Well I have been looking at this thing for hours and I cant understand

...Is there any tutorial I can look at to find out how to do it?
Thanks!
Posted: Wed Jan 19, 2005 8:35 am
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ї'searchtype'];
$searchterm=$HTTP_POST_VARSї'searchterm'];
$searchterm= trim($searchterm);
if (!isset($_SESSIONї'first_name'])) {
header ("Location: http://" . $_SERVERї'HTTP_HOST'] . dirname($_SERVERї'PHP_SELF']) . "/login.php");
ob_end_clean(); // Delete the buffer.
exit(); // Quit the script.
}
if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
include('footer.html');
exit;
}
$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 '{$_GETї'newsort']}' 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ї'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)) {
// Display each record.
echo " <tr>
<td align="center" bgcolor="#FFFFCC"><a href=../fyp/imageuploads/{$rowї'image_name']}><img src="../fyp/imageuploads/{$rowї'image_name']}" alt="{$rowї'image_name']}" height=80 width=80/></a> </td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'song_title']) . "</td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'artist_name']) . "</td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'type']) . "</td>
<td align="center" bgcolor="#FFFFCC">" . stripslashes($rowї'duration']) . "</td>
<td align="center" bgcolor="#FFFFCC"><img src="../fyp/{$rowї'rating']}" alt="{$rowї'rating']}" /> </td>
</td>
</tr>\n";
}
echo '</table></fieldset>'; // Close the table.
include_once('footer.html');
?>
Posted: Wed Jan 19, 2005 10:18 am
by feyd
your code doesn't pass the search parameters searched for initially. Thus losing that information.
Posted: Wed Jan 19, 2005 12:15 pm
by Stelios
Would my problem be solved if I store the $result in another variable?