Jump to content

search results from multiple tables


evanpyrz

Recommended Posts

hey there!

 

what i'm trying to do is have a search page with the query in the url (search.php?q=whatever), have it look up possible results from one table and multiple columns. right now i have the query looking up in the table "account" in the column "username":

 

$colname_SearchUsers = "-1";

if (isset($_GET['q'])) {

  $colname_SearchUsers = $_GET['q'];

}

mysql_select_db($database_World2Kids, $World2Kids);

$query_SearchUsers = sprintf("SELECT * FROM account WHERE username = %s", GetSQLValueString($colname_SearchUsers, "text"));

$SearchUsers = mysql_query($query_SearchUsers, $World2Kids) or die(mysql_error());

$row_SearchUsers = mysql_fetch_assoc($SearchUsers);

$totalRows_SearchUsers = mysql_num_rows($SearchUsers);

 

 

what I'd like to have it do is search in 4 dfferent columns within that table. e.g. first_name and last_name and email.

 

 

any ideas would be appreciated!

Link to comment
https://forums.phpfreaks.com/topic/192778-search-results-from-multiple-tables/
Share on other sites

You would pass all the required search parameters in the querystring, then build your query appropriately.

 

so your url becomes like :

search.php?fn=fred&ln=bloggs&[email protected]

 

then in search.php

 

$firstname = (isset($_GET['fn']))?$_GET['fn']:'';

$lastname = (isset($_GET['ln']))?$_GET['ln']:'';

$email = (isset($_GET['em']))?$_GET['em']:'';

 

Then you do some more checks to see which of those variables is set, and bulid your search query

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.