searching keywords from different databses from my web page
Posted: Thu Feb 24, 2005 9:55 am
i have made a form that includes code which allows me to carry out a search i have three different databses called sofas, wardrobes and coffeetables and basically when you type in certain keywords in the textfield it should display the product
that works fine but i can only search from one database only and when i change the $sql to 1 or 2 in this piece of code
it retrieves the search results from that database
in this code you can see that the little section i have highlighted in bold is why this works
can someone please tell me what to to in order to make sure all the queries can work at the same time
thanks in advance
feyd | please start using
that works fine but i can only search from one database only and when i change the $sql to 1 or 2 in this piece of code
Code: Select all
if ( isset( $sql) && !empty( $sql)){
echo "<!--".$sql."-->";
$result = mysql_query( $sql )
or die("Invalid query: " . mysql_error());Code: Select all
<html>
<head>
<title>Hanover Furniture</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE type="text/css">
<!--
A {
text-decoration:none;
font-weight: bold;
}
A:hover { color:#FF8000 }
.style1 {font-weight: bold}
-->
</STYLE>
<link href="nav.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style3 {font-size: 12px}
a:link {
color: #000000;
}
.style4 {
color: #000000;
font-weight: bold;
}
.style5 {color: #000000}
.style6 {color: #FFFFFF}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body bgcolor="#FEFCD3" vlink="white" alink="blue" style="overflow-x:scroll; overflow-y:hidden;" tracingsrc="dtable.jpg" tracingopacity="49">
<div id="Layer1" style="position:absolute; left:10px; top:49px; width:171px; height:22px; z-index:1"><span class="style1"><font size="5" color="#0000FF">HANOVER</font><font size="5" color="#0099FF">FURNITURE</font><font size="4"></font></span></div>
<div id="Layer1" style="position:absolute; width:96px; height:21px; z-index:1; left: 467px; top: 29px; font-family: Arial, Helvetica, sans-serif; font-size: 14px;">
<div align="center">Quick Search </div>
</div>
<p>&nbsp;</p>
<p> <br>
</p>
<table width="644" height="29" border="0" cellpadding="0" cellspacing="0">
<tr align="right">
<td width="800" bgcolor="#606060">
<div align="right" class="nav style6"><a href="main%20frame.php"> Home |</a> <a href="furniturelink.php">Furniture |</a> <a href="feedback.php" >Feedback |</a> <a href="contactus.php">Contact Us </a> </a> </div></td>
</tr>
</table>
<?php
$link = mysql_connect("linux2.inf.brad.ac.uk", "nmaroof1", "bradford")
or die("Could not connect: " . mysql_error());
mysql_select_db('nmaroof1', $link) or die ( mysql_error());
switch( $_GETї'action'] ){
case "search":
switch( $_GETї'type'] ){
case "home page":
їb]$sqlї/b] = "SELECT sofa_image, sofa_name, sofa_id, description, dimensions, price from sofas WHERE category = '".$_POSTї'tsearch']."'
OR sofa_name ='".$_POSTї'tsearch']."'
OR sofa_id ='".$_POSTї'tsearch']."'";
їb] $sql2ї/b] ="SELECT table_image, table_name, table_id, description, dimensions, price from coffeetables WHERE category = '".$_POSTї'tsearch']."'
OR table_name ='".$_POSTї'tsearch']."'
OR table_id ='".$_POSTї'tsearch']."'";
їb]$sql3ї/b] ="SELECT wardrobe_image, wardrobe_name, wardrobe_id, description, dimensions, price from wardrobes WHERE category = '".$_POSTї'tsearch']."'
OR wardrobe_name ='".$_POSTї'tsearch']."'
OR wardrobe_id ='".$_POSTї'tsearch']."'";
break;
}
break;
}
if ( isset( $sql) && !empty( $sql)){
echo "<!--".$sql."-->";
$result = mysql_query( $sql )
or die("Invalid query: " . mysql_error());
print '<table width="577" height="187" border="0" cellpadding="0" cellspacing="0">';
while($row = @ mysql_fetch_row($result))
{
$imgdir = 'http://linux2.inf.brad.ac.uk:59285/Unnamed%20Site%201/images/' . $rowї0];
print '<tr>';
print "<td width='184' rowspan='3'><img width='240' height='160' border='0' src=$imgdir ></td>";
print '<td width="393" height="33" class="nav">' . $rowї1] . ' id: ' .$rowї2] . '</td>';
print '</tr>';
print '<tr>';
print '<td height="138" class="nav"><div id="Layer1" style="position:absolute; width:180px; height:144px; z-index:1; top: 176px;" class="nav"></div>' .$rowї3] . '</td>';
print '</tr>';
print '<tr>';
print '<td height="38" class="nav">' .$rowї4] . ' ' .$rowї5] . '<hr></td>';
print '</tr>';}
print '</table>';
}
?>
<div id="Layer2" style="position:absolute; width:242px; height:45px; z-index:2; left: 432px; top: 50px;">
<form name="form1" method="post" action="">
<input name="tsearch" type="text" id="tsearch">
<input name="search" type="submit" id="search" value="Search">
</form>
</div>
</body>
</html>in this code you can see that the little section i have highlighted in bold is why this works
can someone please tell me what to to in order to make sure all the queries can work at the same time
thanks in advance
feyd | please start using
Code: Select all
whileCode: Select all
is down!! [/color]