Results 1 to 9 of 9

Thread: How to collect data from multiple tables?
      
   

  1. #1
    Antonio878's Avatar
    Antonio878 is offline Master Sergeant
    Join Date
    Sep 2007
    Posts
    68

    Question How to collect data from multiple tables?

    How can I collect data from multiple tables on bluevoda? I am trying to get data from 2 tables from 1 database but I tried a few ways but didn't work, how will I be able to collect the data from 2 tables in the same database?

  2. #2
    Karen Mac's Avatar
    Karen Mac is offline General
    Join Date
    Apr 2006
    Location
    X marks the spot
    Posts
    8,353

    Default Re: How to collect data from multiple tables?

    you have to have a script on the page laying it out.

    Karen

    VodaHost

    Your Website People!
    1-302-283-3777 North America / International
    07031847328 / United Kingdom

    ------------------------

    Top 3 Best Sellers

    Web Hosting - Unlimited disk space & bandwidth.

    Reseller Hosting - Start your own web hosting business.

    Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)



  3. #3
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: How to collect data from multiple tables?

    I'm not sure what you mean. The easy way is to retrieve the data from the two tables, separately, using "WHERE" clauses to make sure that you retrieve the right ones, then, once you have the data, you can display them in your page.

    Since you are not givin any info on what you are trying to do, what scripts you are using etc, it is not easy to advise you.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  4. #4
    Antonio878's Avatar
    Antonio878 is offline Master Sergeant
    Join Date
    Sep 2007
    Posts
    68

    Default Re: How to collect data from multiple tables?

    Quote Originally Posted by navaldesign View Post
    I'm not sure what you mean. The easy way is to retrieve the data from the two tables, separately, using "WHERE" clauses to make sure that you retrieve the right ones, then, once you have the data, you can display them in your page.

    Since you are not givin any info on what you are trying to do, what scripts you are using etc, it is not easy to advise you.
    Ok this is the php code this is one of the ways I was trying to retrieve data from 2 tables.

    PHP Code:
    $sql "SELECT * FROM name,frame WHERE name='$user' or name='$us'"
    The bolded words are the 2 tables I am trying to get data from. Only those 2 tables.

  5. #5
    Antonio878's Avatar
    Antonio878 is offline Master Sergeant
    Join Date
    Sep 2007
    Posts
    68

    Default Re: How to collect data from multiple tables?

    Quote Originally Posted by navaldesign View Post
    I'm not sure what you mean. The easy way is to retrieve the data from the two tables, separately, using "WHERE" clauses to make sure that you retrieve the right ones, then, once you have the data, you can display them in your page.

    Since you are not givin any info on what you are trying to do, what scripts you are using etc, it is not easy to advise you.
    so would you be able to help me select two or more tables like I showed above? this would really help me out

  6. #6
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default Re: How to collect data from multiple tables?

    Try
    PHP Code:
    $sql "SELECT * FROM name, frame WHERE name.name=frame.name AND name.name='$user' OR name.name='$us'"
    But this is just a general query, I don't know what your table structure is or if the data should be the same in both tables. Either way when selecting from move then one table, you have to explicitly say which column corresponds to what table.

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

  7. #7
    narobe is offline First Lieutenant
    Join Date
    Apr 2006
    Location
    SPAIN
    Posts
    178

    Default Re: How to collect data from multiple tables?

    you can collect data from the tables by:

    $result = mysql_query ( "SELECT * FROM `table1` WHERE 1");
    $result = mysql_query ( "SELECT * FROM `table2` WHERE 1");
    you can then extrat the info from them by

    $row = mysql_fetch_array($result);

  8. #8
    Antonio878's Avatar
    Antonio878 is offline Master Sergeant
    Join Date
    Sep 2007
    Posts
    68

    Default Re: How to collect data from multiple tables?

    Quote Originally Posted by Watdaflip View Post
    Try
    PHP Code:
    $sql "SELECT * FROM name, frame WHERE name.name=frame.name AND name.name='$user' OR name.name='$us'"
    But this is just a general query, I don't know what your table structure is or if the data should be the same in both tables. Either way when selecting from move then one table, you have to explicitly say which column corresponds to what table.
    how do I apply that code to this cause I tried but didn't work out so I think I did it wrong:

    PHP Code:
    <?php
    $rec_limit 
    10;
    $conn mysql_connect("localhost","user","password");
    if (!
    $conn)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("oieieais_Comment"$conn);
    $sql "SELECT count(id) FROM $useri, $username WHERE name='$username' or name='$useri'";
    $retval mysql_query$sql$conn );
    if(! 
    $retval )
    {
      die(
    'Could not get data: ' mysql_error());
    }
    $row mysql_fetch_array($retvalMYSQL_NUM );
    $rec_count $row[0];
    if( isset(
    $_GET{'page'} ) )
    {
       
    $page $_GET{'page'} + 1;
       
    $offset $rec_limit $page ;
    }
    else
    {
       
    $page 0;
       
    $offset 0;
    }
    $left_rec $rec_count - ($page $rec_limit);
    $sql "SELECT *".
           
    "FROM $useri, $username WHERE name='$username' or name='$useri'".
           
    " ORDER BY tm DESC LIMIT $offset, $rec_limit";
    $retval mysql_query$sql$conn );
    if(! 
    $retval )
    {
      die(
    'Could not get data: ' mysql_error());
    }
    while(
    $nt=mysql_fetch_array($retvalMYSQL_ASSOC)){
    }
    mysql_close($conn);
    ?>

  9. #9
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default Re: How to collect data from multiple tables?

    Well I still don't know your table structure so I can't say exactly what your query should be, but heres some problems with your script

    1) You are using variables for your tables in your sql query. While you can do this, your using the same variables as column values and neither have been set to anything. If you look closly at what I posted before the tables that you are selected need to be specified with the columns, look at the color coding.
    "SELECT * FROM name, frame WHERE name.name=frame.name AND name.name='$user' OR name.name='$us'"
    Blue is the table, red is the column your selecting

    2) Your logic for getting the correct page is wrong, instead of doing
    PHP Code:
    if( isset($_GET{'page'} ) )
    {
       
    $page $_GET{'page'} + 1;
       
    $offset $rec_limit $page ;
    }
    else
    {
       
    $page 0;
       
    $offset 0;

    you should do
    PHP Code:
    $page $_GET['page'];
    if(
    $page 1)
    {
        
    $page 1;
    }
    $offset $rec_limit * ($page 1); 
    This will also leave $page for use in your links to the next page, and won't skip records 10-19 like your code will now.

    3) I don't know if you were using $left_rec somewhere, but its not being used in that script, you can get rid of it.

    4) When your retrieving your url variable with GET you are using curly brackets. While this is valid syntax, you should always try to follow normal programming convention and use square brackets with arrays.

    Register/Login Script
    Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49