Results 1 to 3 of 3

Thread: Selecting Multiple Tables

  1. #1
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default Selecting Multiple Tables

    Hi guys...

    Don't know if this is possible, it should be in some way.

    i'm trying to selected several rows ranging across several tables within the same DB at the same time.

    I have a field in each table called "feature" and I want to select all that have a value of "1" across the DB.

    How can i do this?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There may be a way to create a temporary table, merge them temporarily, etc., and output at the same time, though you might find it more reasonable to just do this through php using several queries at the same time.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Try this:
    PHP Code:
    <?php
    $tables 
    = array('table1','table2');
    $row=array();
    foreach (
    $tables as $table) {
        
    $sql "SELECT * FROM `$table` WHERE feature='1'";
        
    $result mysql_query($sql);
        while (
    $r mysql_fetch_assoc($result))    {
            foreach (
    $r as $name=>$value)    {
                
    $row[] = $value;
            }
        }
    }
    ?>
    It puts all the results into the array $row.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •