473,513 Members | 2,420 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 2014
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******@pacbell.net> wrote in message news:<Pv*****************@newssvr21.news.prodigy.c om>...
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*****@firstdbasource.com> wrote in message
news:Lu*****************@newssvr24.news.prodigy.co m...
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($query);
if ($result) {
while ($r = mysql_fetch_array($result) {
$id = $r["id"];

$query2 = "SELECT * FROM otherTable where id = '$id'";
$result2 = mysql_query($query2);
if ($result) {
while ($r2 = mysql_fetch_array($result2) {
$colfrom2ndtable = $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
13263
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...
3
53715
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...
2
8466
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...
7
1287
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: ...
3
7645
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...
2
5744
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...
0
2303
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...
3
7747
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...
3
2220
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...
11
2818
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...
0
7259
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
7158
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...
0
7380
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,...
1
7098
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
5683
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,...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1592
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.