473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

multiple queries to multiple tables

I have 3 different tables in one database and need to display the info off each table in a separate html table.

I'm looking to see if my concept is correct. In my code below, I'm not writing all the exact syntax, just trying to illustrate my thought process.

First I'm going to grab the variable from the URL (this is a common family ID for all 3 tables)

Then I'm going to do my first query off of the first table something like this -
Expand|Select|Wrap|Line Numbers
  1. $query1="select * from table_1 where family ID like $var"
then I will get the results and display them in a table -
Expand|Select|Wrap|Line Numbers
  1.     $result1=mysql_query($query1)
  2.     while $row=$result
  3. <tr>
  4.   <td>$1</td>
  5.   <td>$2</td>
  6. </tr>
Then what I want to do is use the same variable that I pulled from the URL as a query on the second table, like this:
Expand|Select|Wrap|Line Numbers
  1. query2="select * from table_2 where ID like $var"
then I will get the results and display them in a table -
Expand|Select|Wrap|Line Numbers
  1.     $result2=mysql_query($query2)
  2.     while $row=$result2
  3. <tr>
  4.   <td>$1_1</td>
  5.   <td>$2_1</td>
  6. </tr>
Is this the right idea to achieve what I'm looking to do?
Jul 24 '07 #1
2 1286
pbmods
5,821 Expert 4TB
Heya, RoomfulExpress. Welcome to TSDN!

Looks good so far.
Jul 24 '07 #2
Here's the exact code that I'm using. It's working like a charm so far. Any way to make it better? I'm still kind of new to php and I got the concepts, just all the syntax and tricks require time to learn...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Roomful Express Sofa Search</title>

<!--<link href="profile.css" rel="stylesheet" type="text/css" />
<link href="../css/slimbox.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/mootools.v1.11.js"></script>
<script type="text/javascript" src="../js/slimbox.js"></script> -->

</head>

<body>
<div class="container">

<?php

// Get the search variable from URL

$var = @$_GET['FAMILY_CD'] ;
$trimmed = trim($var); //trim whitespace from the stored variable

//connect to your database ** EDIT REQUIRED HERE **
mysql_connect("sql002.choiceone.net","roomfulexpre ss","x47rkv7N"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
mysql_select_db("roomfulexpress") or die("Unable to select database"); //select which database we're using

// Build SQL Query
$query = "select * from tblFamily where FAMILY_CD like \"%$trimmed%\" order by FAMILY_NAME"; // this will only effect the data pulling from the family table

$result = mysql_query($query) or die("Couldn't execute query"); // grab results

while ($row = mysql_fetch_array($result)) // show results

{
echo("<table width=500px>");
echo("<tr>");
echo("<td> ". $row["FAMILY_NAME"] . "</td>");
echo("</tr>");
}
echo("</table>");

// Build SQL Query
$query2 = "select * from tblItem where FAMILY_CD like \"%$trimmed%\" order by ITEM_NAME"; // this will only effect the data pulling from the family table

$result2 = mysql_query($query2) or die("Couldn't execute query"); // grab results

while ($row = mysql_fetch_array($result2)) // show results

{
echo("<table width=500px>");
echo("<tr>");
echo("<td> ". $row["ITEM_NAME"] . "</td>");
echo("</tr>");
}
echo("</table>");

// Build SQL Query
$query3 = "select * from tblFurniture where FAMILY_CD like \"%$trimmed%\" order by ITEM_NAME"; // this will only effect the data pulling from the family table

$result3 = mysql_query($query3) or die("Couldn't execute query"); // grab results

while ($row = mysql_fetch_array($result3)) // show results

{
echo("<table width=500px>");
echo("<tr>");
echo("<td> ". $row["MINOR_CD"] . "</td>");
echo("<td> ". $row["SKU"] . "</td>");
echo("</tr>");
}
echo("</table>");


?>
<!--<div class="smallerFontLeft"><A HREF="javascript:window.print()"> <img src="../images/common/print.jpg" align="bottom" /> click to print this profile</A></div>
<div class="smallFontLeft"><A HREF="javascript:history.go(-1)"> &lt;&lt;Back</A></div></div>
</div>-->
</body>
</html>
Jul 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
1
by: fong.yang | last post by:
I've got a database with about 300,000 records. There are several different tables that are set up the same way with identical fields. I have the same queries individually set up for each table. ...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.