Computing.Net > Forums > Database > search in one of four tables

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

search in one of four tables

Reply to Message Icon

Name: andy84
Date: April 6, 2007 at 13:46:51 Pacific
OS: win XP
CPU/Ram: 3 GHz / 2 GB
Product: Intell / Kingstone
Comment:

Hi I have form for searching one of four types here is my syntax for select :

$query = "SELECT * FROM '$jobs' WHERE location ='$search'";

$jobs should show one of this:

<select name="jobs" class="box">
<option value="" class="box">Select...</option>
<option value="admin_jobs" class="box">Admin Jobs</option>
<option value="retail_jobs" class="box">Retail Jobs</option>
<option value="beauty_jobs" class="box">Beauty Jobs</option>
<option value="promotion_jobs" class="box">Promotion Jobs</option>
</select>

So I can seperatly search one of this four tables

I have problem to put this together with my PHP script which look like this

<?
if ($search) // perform search only if a string was entered.
{
mysql_connect("localhost","root","") or die ("Problem connecting to Database");

$query = "SELECT * FROM '$jobs' WHERE location ='$search'";

$result = mysql_db_query("prolinc", $query);

if ($result)
{
echo "Here are the results:

";
echo "<table width=90% align=center border=0><tr>
<td align=center bgcolor=#00FFFF>Position</td>
<td align=center bgcolor=#00FFFF>Location</td>
<td align=center bgcolor=#00FFFF>Salary</td>
<td align=center bgcolor=#00FFFF>Duration</td>
</tr>";

while ($r = mysql_fetch_array($result)) { // Begin while
$salary = $r["salary"];
$location = $r["location"];
$position = $r["position"];
$duration = $r["duration"];
$sdesc = $r["sdesc"];
$requirements = $r["requirements"];
$company = $r["company"];
echo "
<tr> <td colspan=4 bgcolor=\"#333333\"></td></tr>
<tr>
<td>$position</td>
<td>$location</td>
<td>$salary</td>
<td>$duration</td></tr>
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$sdesc</td></tr>
<tr> <td colspan=4 bgcolor=\"#333333\"></td></tr>";
} // end while

echo "</table>";
}

else { echo "problems...."; }
}
else {
echo "Search string is empty.
Go back and type a string to search";
}

?>

as you can see if I will replace $jobs using one of admin_jobs or other it will start search this one table - can you advice how can I doo it so I can choose one ;/




Sponsored Link
Ads by Google

Response Number 1
Name: andy84
Date: April 7, 2007 at 01:31:35 Pacific
Reply:

there was easy way just I have this:

$query = "SELECT * FROM '$jobs' WHERE location ='$search'";

and I change it to :

$jobs=$_POST['jobs'];
$query = "SELECT * FROM $jobs WHERE location ='$search'";

and it works fine :)


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: search in one of four tables

Newline character in data field of sybase www.computing.net/answers/dbase/newline-character-in-data-field-of-sybase/721.html

Access 2000 query result www.computing.net/answers/dbase/access-2000-query-result/272.html

Access 97 - Save as HTML www.computing.net/answers/dbase/access-97-save-as-html/66.html