Working with a table from inside a databse row

This is a discussion on Working with a table from inside a databse row within the PHP Language forums, part of the PHP Programming Forums category; I have a simple site layout. Everything is being pulled from a database in such fashion that Page 1 of ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2006
maxvalery@gmail.com
 
Posts: n/a
Default 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?

Reply With Quote
  #2 (permalink)  
Old 04-20-2006
milahu
 
Posts: n/a
Default 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.

Reply With Quote
  #3 (permalink)  
Old 04-20-2006
maxvalery@gmail.com
 
Posts: n/a
Default 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, pageMiddleContent,
pageRightContent)

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.pageMiddleContent' field?

Thanks.

Reply With Quote
  #4 (permalink)  
Old 04-20-2006
milahu
 
Posts: n/a
Default Re: Working with a table from inside a databse row

> Are you suggesting INSERTing entire tbl_Products code directly into the
> 'tbl_siteLayout.pageMiddleContent' field?


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

Reply With Quote
  #5 (permalink)  
Old 04-21-2006
maxvalery@gmail.com
 
Posts: n/a
Default 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().

Reply With Quote
  #6 (permalink)  
Old 04-21-2006
milahu
 
Posts: n/a
Default Re: Working with a table from inside a databse row

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


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

Cheers

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:09 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0