470,604 Members | 2,179 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

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 1872
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Don Wash | last post: by
3 posts views Thread by mnjkahn via AccessMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.