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!
Moderator: General Moderators
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');
?>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');
?>