Working with a table from inside a databse row

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • maxvalery@gmail.com

    Working with a table from inside a databse row

    I have a simple site layout. Everything is being pulled from a
    database in such fashion that Page 1 of the site is referenced by
    'pagename.php/?id=1', Page 2 is referenced by 'pagename.php/?id=2', and
    so forth. In other words, I have only one page 'pagename.php' with a
    couple of conditional statements and a navigation bar as a form using
    method "get".

    I need the middle content part on page 'pagename.php/?id=3' to pull
    some information from a completely separate table. Is there a way to
    accomplish that without resorting to

    if ($_GET[id] = 3) {
    // do a completely separate page layout with data pulled by the
    needed page
    }

    I don't want to hardcode the condition because a user may delete row
    where id=3.

    Basically, is there a way to run a database query from inside a
    database row while in phpMyAdmin?

  • milahu

    #2
    Re: Working with a table from inside a databse row

    You can simply add a block of PHP code to the page content in the DB
    and have it parsed by eval().

    PS: Don't kill me for suggesting eval(). It's the most simple and
    flexible solution here.

    Comment

    • maxvalery@gmail.com

      #3
      Re: Working with a table from inside a databse row

      Thank you for replying. Could you be more specific, please?

      Again, it goes something like this:

      Table structure
      tbl_siteLayout (ID, pageName, pageLeftContent , pageMiddleConte nt,
      pageRightConten t)

      The navigation bar is pulling ID, creates 'pagename.php/?id=' links,
      and the 'pagename.php' uses $_GET to run a query where id = $_GET[id]
      to display all content.

      One of those pages referenced by id=3 needs to contain a list of
      products pulled out of tbl_Products (productID, productName,
      productDesc, productPrice).

      Are you suggesting INSERTing entire tbl_Products code directly into the
      'tbl_siteLayout .pageMiddleCont ent' field?

      Thanks.

      Comment

      • milahu

        #4
        Re: Working with a table from inside a databse row

        > Are you suggesting INSERTing entire tbl_Products code directly into the[color=blue]
        > 'tbl_siteLayout .pageMiddleCont ent' field?[/color]

        No, just store sth. like
        -----
        <ul>
        <?php
        // connect to mysql, query and parse result
        ?>
        </ul>
        -----
        in the database and instead of printing the contents pass them to
        eval():
        -----
        <?php
        // fetch $content from mysql
        eval($content);
        ?>
        -----
        Since you don't have access to variables as you would have with
        include(), you have to connect to mySQL in the eval'ed code separately.

        Cheers, milahu

        Comment

        • maxvalery@gmail.com

          #5
          Re: Working with a table from inside a databse row

          Thanks!

          I didn't realize I had to jump through this little hoop:

          eval ("?>" . $row['centercontent'] . "<?php ");

          Why do you have to use those tags in this case? (?>, <?)

          Eval() should be called Evil().

          Comment

          • milahu

            #6
            Re: Working with a table from inside a databse row

            maxvalery@gmail .com wrote:[color=blue]
            > Why do you have to use those tags in this case? (?>, <?)[/color]

            eval() parses in `PHP-mode', so you have to close and re-open the PHP
            tags when passing HTML contents to it.

            Cheers

            Comment

            Working...