Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

A PHP question -- inserting code from SQL

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

A PHP question -- inserting code from SQL

Post by daj »

For all you PHP gurus out there...I wish to read some data from an SQL table and have the result as part of the HTML page

Getting the data from SQL is fine, and I can then "echo" the result. However if the result contains HTML/PHP code itself I would like PHP to process it first.

Example, the returned field from SQL contains this text

Code: Select all

<b>Testing</b> <?php echo "123"; ?>
When the HTML page is shown I get

Testing Where as I want Testing 123

I thought if I used the eval() rather than echo, but no :(

I am sure I am missing something really simple! :o

(I know this is not a PHP forum, but we have some good guys on here)
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: A PHP question -- inserting code from SQL

Post by daj »

I think I have answered it myself. I did spend about 30 mins on Google this morning on this, but gave up, wrote this post, had a break and started searching again....

So I do use the eval function but I need to close my PHP tag first

Code: Select all

eval (" ?>" . $row['message'] );
Initially I did not have the " ?>", but I can see it makes sense now to close the PHP first rather than throw a mix of html & php into an alreafy open php!
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A PHP question -- inserting code from SQL

Post by beteljuice »

Why are you using eval when there are php / sql interfaces / queries ?
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: A PHP question -- inserting code from SQL

Post by daj »

Hi 'Bet',

Can you explain further?

I used eval() as I need the PHP processor to process my SQL inserted data, and not just treat it as plain text that it throws onto the page.

is there a better way?
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: A PHP question -- inserting code from SQL

Post by beteljuice »

Not my bag, I work with flat files, but I am under the impression that there are some direct php 'interfaces' to mysql, and the ability to pass mysql command syntax.
Image
......................Imagine, what you will KNOW tomorrow !
Post Reply