Using a query on a query (or view)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Victor

    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


  • Michael Austin

    #2
    Re: Using a query on a query (or view)

    John Victor wrote:[color=blue]
    > 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?[/color]

    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
    :)

    Comment

    • chotiwallah

      #3
      Re: Using a query on a query (or view)

      "John Victor" <wiegeabo@pacbe ll.net> wrote in message news:<PvBWc.753 9$QJ3.7225@news svr21.news.prod igy.com>...[color=blue]
      > 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.[/color]

      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

      Comment

      • John Victor

        #4
        Re: Using a query on a query (or view)

        Unfortunately, I have to use MySQL 4.x

        John


        "Michael Austin" <maustin@firstd basource.com> wrote in message
        news:LuIWc.4834 $Jf7.4819@newss vr24.news.prodi gy.com...
        [color=blue]
        > Or if you are using MySQL 5.0.0.1 then you can actually create and use a[/color]
        view.[color=blue]
        >
        > --
        > Michael Austin.
        > Consultant - Available.
        > Donations welcomed. Http://www.firstdbasource.com/donations.html
        > :)[/color]


        Comment

        • Mark Kuiphuis

          #5
          Re: Using a query on a query (or view)

          <?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:
          [color=blue]
          > 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.
          >
          >
          >
          >[/color]

          Comment

          Working...