Jump to content

mysql_field_table not working the way I want it to


Guest

Recommended Posts

I have a mysql select statement that looks like this:

 

$searchQuery = "SELECT title, content FROM pages WHERE title LIKE '%$searchString%' OR content LIKE '%$searchString%' UNION (SELECT title, content FROM posts WHERE title LIKE '%$searchString%' OR content LIKE '%$searchString%') UNION (SELECT title, content FROM comments WHERE title LIKE '%$searchString%' OR content LIKE '%$searchString%') UNION (SELECT title, content FROM events WHERE title LIKE '%$searchString%' OR content LIKE '%$searchString%')";
$searchResult = mysql_query($searchQuery) or die("Error in query $searchQuery: " . mysql_error());
list($itemTitle, $itemContent) = mysql_fetch_row($searchResult);

 

Then I want the page to direct the user to page.php if the result is from the pages table, post.php if the result is from the posts table, comment.php if the result is from the comments table, and event.php if the result is from the events table. This is the part that isn't working:

 

if (mysql_field_table == 'pages') {
  $link = 'page.php';
} elseif (mysql_field_table == 'posts') {
  $link = 'post.php';
} elseif (mysql_field_table == 'comments') {
  $link = 'comment.php';
} else {
  $link = 'event.php';
}

 

However, when the page is rendered it thinks everything is an event and links each item in the search result to event.php. How do I fix this? Is there a simpler method?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.