Below is my code which is finally functioning and pulling back the results from the database. However, it's searching only the "type" attribute in the table. I want it to search the type, title, author and then the body columns. The problem is, I want them to come back in a prefered order.
So say someone searches for "Soldier" and there's an article's title called "US soldiers around the world" that would obviously be more related than having the same word burried down in the body of some rather unrelated article. How do I give precedence to the fields and control the order that they results come back?
<?php
// This is supplied by the user in a previous page
$searchtopic = $_POST['searchtopic'];
// Formulate Query
$query = sprintf("SELECT * FROM data_array WHERE type='%s'", mysql_real_escape_string($searchtopic));
// Perform Query
$result = mysql_query($query);
// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
?>
</p>
<?php do { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="80"><p><?php echo $row['id']; ?></p></td>
<td><?php echo $row['title']; ?></td>
<td><div align="right">
<?php echo $row['date']; ?></div></td>
</tr>
</table>
<?php } while ($row = mysql_fetch_assoc($result));
mysql_free_result($result);?>