Hi,
I have a search box which allows you to look up something and display. What i cant figure out is how to amend the script to display, for example, 5 random stories.
Any help is appreciate. The code used to display the search is below
I have a search box which allows you to look up something and display. What i cant figure out is how to amend the script to display, for example, 5 random stories.
Any help is appreciate. The code used to display the search is below
Code:
// The basic SELECT statement
$select = 'SELECT DISTINCT id, joketext';
$from = ' FROM joke';
$where = ' WHERE 1=1';
$aid = $_POST['aid'];
if ($aid != '') { // An author is selected
$where .= " AND authorid='$aid'";
}
$cid = $_POST['cid'];
if ($cid != '') { // A category is selected
$from .= ', jokecategory';
$where .= " AND id=jokeid AND categoryid='$cid'";
}
$searchtext = $_POST['searchtext'];
if ($searchtext != '') { // Some search text was specified
$where .= " AND joketext LIKE '%$searchtext%'";
}
?>
<table>
<tr><th>Joke Text</th><th>Options</th></tr>
<?php
$jokes = @mysql_query($select . $from . $where);
if (!$jokes) {
echo '</table>';
exit('<p>Error retrieving jokes from database!<br />'.
'Error: ' . mysql_error() . '</p>');
}
while ($joke = mysql_fetch_array($jokes)) {
echo "<tr valign='top'>\n";
$id = $joke['id'];
$joketext = htmlspecialchars($joke['joketext']);
echo "<td>$joketext</td>\n";
echo "<td><a href='editjoke.php?id=$id'>Edit</a> | " .
"<a href='deletejoke.php?id=$id'>Delete</a></td>\n";
echo "</tr>\n";
}
?>
</table>
Comment