User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,590 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,685 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1401 | Replies: 2
Reply
Join Date: Apr 2005
Posts: 15
Reputation: vipula is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vipula vipula is offline Offline
Newbie Poster

Search two databases

  #1  
May 6th, 2005
Hello Experts !!!

I have two databases to select from my web page. In this script i can search one database(if ($choice=="staff publication") it works. I dont know how to write the script if I select the other option if($choice=="books"). Please can any one help me. I want to display search resuls of "books" the same way as staff publications. but books database has different fields.

if($choice=="books){
$query="SELECT * FROM books WHERE match (authors, title, callnumber keywords, edition, year, notes) against ('$name' in boolean mode) ORDER BY year DESC";
}
I want to put the above somewhere in the script and display results.

<?php
$link = mysql_connect('localhost', 'root', 'vip');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('test1');

@mysql_select_db(test1) or die("unable to connect");

$choice=$_POST['choice'];
$name=$_POST['name'];

if ($choice=="staff publications"){

$query="SELECT * FROM staffpub WHERE match (authors, title, source, keywords, mesh, year, notes) against ('$name' in boolean mode) ORDER BY year DESC";

}


$result=mysql_db_query("test1", $query);
$num_rows = mysql_num_rows($result);
if ($num_rows==0){$search_result="<p class='error'>No Results Found</p>";}
elseif ($num_rows > 0){$search_result="<p class='error'>".$num_rows. " Results Found</p>";}


mysql_close();

echo '<b><center><font size="4" color="#FF0000">Search Result</font></center></b><br><br>';

$i=0;
while ($i < $num_rows) {

$authors=mysql_result($result,$i,"authors");
$title=mysql_result($result,$i,"title");
$source=mysql_result($result,$i,"source");





echo "<b>Authors:</b> $authors<br><b>Title:</b> $title<br><b>Source:</b> $source<br><br><hr><br>";

$i++;

?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Location: San Francisco, CA
Posts: 337
Reputation: paradox814 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Search two databases

  #2  
May 6th, 2005
well you would need to have
mysql_select_db('books');
somewhere in there to actually use that database
Reply With Quote  
Join Date: Apr 2005
Posts: 15
Reputation: vipula is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vipula vipula is offline Offline
Newbie Poster

Re: Search two databases

  #3  
May 6th, 2005
Dear Paradox

I am sorry i made a mistake. it is not two databases. it should be two tables. i will rectify it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 11:20 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC