multiple tables in one page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imarkdesigns
    New Member
    • Jul 2007
    • 46

    multiple tables in one page

    Good day to all MASTERS!!

    i have a simple problem here right now, and i think any PHP/MySQL Masters here can help me...

    anyway, i have 3 tables in 1 Database. category1 , category2 , and category3 . these tables will be viewed in one page. but the problem is, how can i possibly code this? anyone?

    here is my actual coding before... if there's any corrections... i appreciate it very much !

    [PHP]$query = "SELECT category1.*, category2.*, category3.* FROM `category1` INNER JOIN `category2` IN `category1` = `category2` INNER JOIN `category3` IN `category3` = `category2` ORDER BY `id` DESC LIMIT $offset, $rowsPerPage";[/PHP]

    by the way, this code is under and running by pagination..
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I think you have got a bit confused with your query.
    You connect to a Database then select Fields from Tables.
    If they are three similar tables a UNION looks promising.
    Can't give a query because I can't work out what you are trying to do.
    [PHP]$query = "SELECT category1.*, category2.*, category3.* FROM `category1` INNER JOIN `category2` IN `category1` = `category2` INNER JOIN `category3` IN `category3` = `category2` ORDER BY `id` DESC LIMIT $offset, $rowsPerPage";[/PHP]But Use ON not IN with a JOIN.
    You cannot ORDER BY something you haven't selected

    Comment

    • imarkdesigns
      New Member
      • Jul 2007
      • 46

      #3
      hhmm....

      ok... (by the way, im not a developer or programmer :( so it is not very easy for me to understand all type of codings here but i will try my best)

      i have these categories in database, categery1, category2 and category3... what i want to do is to mix (not combine although their values are all same) these 3 tables in one page..

      now, i just wondering how can i possibly write the exact code for this that will display mixture of 3 categories in one page...

      Comment

      • imarkdesigns
        New Member
        • Jul 2007
        • 46

        #4
        multiple tables in one page

        here is my full actual codes.. and i use only 1 category

        [PHP]
        <?php

        include 'admin/library/config.php';
        include 'admin/library/opendb.php';

        $query = "SELECT * FROM `category1` ORDER BY `id` DESC ";
        $result = mysql_query($qu ery) or die('Error, insert query failed');

        while($rows = mysql_fetch_arr ay($result)) {

        ?>
        <div class="list1">

        <div class="thumbs">
        <form action="descrip tion.php" method="get">
        <input type="image" src="box/<? echo $rows['name']; ?> " />
        <input type="hidden" name="id" value="<? echo $rows['id']; ?>" />
        </form>
        </div>
        <ul class="connecti on">
        <li class="ctitle"> <a href="<? echo $rows['website']; ?>" target="_blank" ><? echo $rows['title']; ?></a></li>
        <li class="category "><? echo $rows['category']; ?></li>
        </ul>
        </div>
        <?php

        }
        include 'admin/library/closedb.php';

        ?>

        [/PHP]
        Last edited by imarkdesigns; Nov 6 '07, 06:28 PM. Reason: update

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Originally posted by code green
          You cannot ORDER BY something you haven't selected
          Sure you can. As long as the table(s) that contains the field(s) is (are) part of the query.

          Comment

          • code green
            Recognized Expert Top Contributor
            • Mar 2007
            • 1726

            #6
            You cannot ORDER BY something you haven't selected
            Sure you can. As long as the table(s) that contains the field(s) is (are) part of the query
            Aaaarrrgh. Sorry pbmods imarkdesigns.
            I was getting confused with GROUP BY and aggregation.
            what i want to do is to mix (not combine although their values are all same) these 3 tables in one page
            Not quite sure what you are doing,
            but if you are selecting the same number of fields from the three tables a UNION may work [PHP]$query = "SELECT * FROM `category1` ORDER BY `id` DESC
            UNION SELECT * FROM `category2` ORDER BY `id` DESC
            UNION SELECT * FROM `category3` ORDER BY `id` DESC ";[/PHP]
            Please check I got the syntax right.
            I don't want pbmods shouting at me again

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              When pbmods shouts, he breaths a breath of knowledge and a shower of evermore knowledgable spit, over your face.

              Feel blessed!

              Comment

              Working...