I am trying to have a search bar where user will input a string ($var) which after i will search that sting in the field named: "itemname". i will search all the different tables in the database and create a new temporary database named: searchtable. seachtable should contain all the data where itemname was $var. Then i want to select the data from the new database and display it.


Sounds simple right? wrong! :) i am having issues.
Please help

here is my query statement:

$query = "Select * INTO searchtable from art WHERE itemname like \"%$trimmed%\" UNION ALL Select * INTO searchtable from cellphone WHERE itemname like \"%$trimmed%\"";

after when i try to select i do not get any data.

How long does a temporary table stays for?
Thank you

why do you need to make a new table just get all your queries into an associative array
like

while($row = mysqli_fetch_array($link, $sql)
{
$search = array('searchitem' => $row['searchitem'])
}

then you output the results it got in your html with link to the content and such

i dont think i follow this method. what will my query will look like? what is $link?
how would i access $search? i am very weak with arrays, much rather have a temp table. is that possible? i know how to access tables easily.
in my tables i have all the same fields: id, name, email ,phone, picname, picpath.
Like i said before i need to find what the user is searching for. When i access the data i will need to go back and access it twice. once to pull a filename and the second time after some other code to access phone and name.

you need to make sure your SQL is correct try it out in your MySQL console and see if it returns results.
second look up While and Foreach loops online and how they can be used for arrays
there is a lot of content already written on how to take your SQL results and put them in an array google it

i think i understand as i read all day about arrays and 2 dimensional array.
still i am not sure what ,

while($row = mysqli_fetch_array($link, $sql)

$link and $sql means?

ok $link and $sql are your variables so

$link = mysqli_connect('localhost', 'root', '[I]password[/I]');
mysqli_connect_db($link, '[I]database[/I]');
$sql = [I]your sql[/I];

you need to look up build you own database driven website using php and mysql by kevin yank it will teach you a lot

this is the code you want to get from you database then put it in an array (change array values to your values

if(!$link)
{
$error = 'Cannot Connect to DB';
include 'error.html.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$error = 'Unanle to set encoding!';
include 'error.html.php';
exit();
}
if(!mysqli_select_db($link, 'cmte'))
{
$error = 'unable to select database!';
include 'error.html.php';
exit();
}
[I]example sql[/I]
$sql = 'SELECT [I]column names[/I]
FROM [I]tablename[/I] where [I]searchitem[/I] like "%$trimmed%"'

$result = mysqli_query($link, $sql);
while($query = mysqli_fetch_array($result))
{
$search[] = array('name' => $query['name'], 'id' => $query['id'], 'otheritem' => $query['otheritem']);

}
}

I am totally agree with the tape enterprise coding example . I ran the code and i got the relevant result

dude thank you!!!! i tried it and it works like a charm now. i even put it in a nice function file. awesome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.