473,770 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a query on a query (or view)

In my php page I'm using a mysql database. I want to run a query on a
table, then run a second query on the results returned from the first query.
In mysql this would be the same as running a query on a table to create a
view, and then running a query on the resulting view. What is the php
equivalent of this?

Thanks.


--
John
Jul 17 '05 #1
4 2026
John Victor wrote:
In my php page I'm using a mysql database. I want to run a query on a
table, then run a second query on the results returned from the first query.
In mysql this would be the same as running a query on a table to create a
view, and then running a query on the resulting view. What is the php
equivalent of this?


looping through the results looking for the results you expect.

look at preg_match and related string matching functions.

Or if you are using MySQL 5.0.0.1 then you can actually create and use a view.

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #2
"John Victor" <wi******@pacbe ll.net> wrote in message news:<Pv******* **********@news svr21.news.prod igy.com>...
In my php page I'm using a mysql database. I want to run a query on a
table, then run a second query on the results returned from the first query.
In mysql this would be the same as running a query on a table to create a
view, and then running a query on the resulting view. What is the php
equivalent of this?

Thanks.


you could create a temporary table from your 1st query and use that like a view.
see http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html

micha
Jul 17 '05 #3
Unfortunately, I have to use MySQL 4.x

John
"Michael Austin" <ma*****@firstd basource.com> wrote in message
news:Lu******** *********@newss vr24.news.prodi gy.com...
Or if you are using MySQL 5.0.0.1 then you can actually create and use a view.
--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)

Jul 17 '05 #4
<?php
$query = "SELECT id FROM table";
$result = mysql_query($qu ery);
if ($result) {
while ($r = mysql_fetch_arr ay($result) {
$id = $r["id"];

$query2 = "SELECT * FROM otherTable where id = '$id'";
$result2 = mysql_query($qu ery2);
if ($result) {
while ($r2 = mysql_fetch_arr ay($result2) {
$colfrom2ndtabl e = $r2["name"];
}
}
}
}
?>

Regards....

Mark

Another way is to put the results of $result in an array. Then (outside
the while-loop) do a for-loop and wlak through the results in the array
and use the id.
John Victor wrote:
In my php page I'm using a mysql database. I want to run a query on a
table, then run a second query on the results returned from the first query.
In mysql this would be the same as running a query on a table to create a
view, and then running a query on the resulting view. What is the php
equivalent of this?

Thanks.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
13298
by: NB | last post by:
Hi Is there any way to call up the query design view from code? In my compiled-as-MDE app everything is hidden from end users. However, I want advanced user to have access to the query design view so they can create, run and export their own query. Another question is: can they be prevented from saving those on-the-fly queries?
3
53772
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have a specific need to only add a new field to a table if possible. Here's a simplified example of what I'm trying to do: I get a file with the following two fields: First Name
2
8487
by: Don Wash | last post by:
Hi All! I've been searching everywhere for a simple sample of producing a bar graph using CrystalReport by specifying SQL Query, and I've found none of it! I find so many complex samples with so many features buried in the sample but all I want to know is a very simple thing, how to create bar charts with CrystalReport in VS.NET using SQL Query. Could anyone provide me a sample showing how to produce a simple bar chart using SQL Query...
7
1293
by: Rob Richardson | last post by:
Greetings! I am rewriting a VB6 application in VB .Net. The database (which was converted from Access 97 into Access 2000) has two nearly identical queries. One, called GetNewOrderNumber, is: SELECT IIF ((SELECT COUNT(*) FROM Orders), Max(Order_number) + 1, 1) AS NewOrderNumber FROM Orders;
3
7679
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the error below. Can I access a Web Service through a Query Sting. I need to send XML to a Flash movie using a Web Service. Thank You, Jim Lewis Server Error in '/WebService1' Application.
2
5762
by: NowItsWhatever | last post by:
In query DESIGN view, how do I automatically "fit" the columns in the table/field grid to the lengths of the table and field names (including any functions applied to the fields). I am not talking about the query results. I am talking about sizing parts of the query DESIGN view, so that they are readable (long table and field names that get chopped off, long criteria specifications that get chopped off, ...), and saving the sizing so I...
0
2323
by: Peter Herath | last post by:
I want to create a custormizable report . For an example, there's a form with four combo boxes and two of them having database tables columns/field names as values in the combo box(one for select row filed and other one for select column filed in the report) when u select items in that combo boxes and press a Button then selected items should go to the crosstab query as parameters and execute the query. upto that i have done my coding part but...
3
7772
by: mnjkahn via AccessMonster.com | last post by:
I'm running Access 2003, modifying a query that has over 45 fields. When I right click on the field name in Query Design View, and then click Build, Access crashes before the Build window appears. It doesn't happen every time, and using the Zoom window works fine. It appears that it only happens when I want to modify an existing expression. This continues to happen even after the database is repaired and reopened. Anyone have any...
3
2236
accessbunnie
by: accessbunnie | last post by:
Hello Access Users! I am a bit of an Access novice and am currently creating a database and have come up against a huge (for me!) road block. I do not write in Access code and instead, tend to just use design view and wizards to create my databases. I created a form using a query I created composed of two different tables with the same unique identifier. All things went fine while I dragged my variables from the field list to the...
11
2842
f430
by: f430 | last post by:
i have created a query using the sql view, and want to make this query a table. is there any way i can do that. i have tried clicking on query-make table query, but this takes me to the design view and it completely neglects what i had in sql view. Thanks
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.