Solved

How can i improve my site architecture so that i'm not trying to run dynamic code in a mysql db?

Posted on 2008-11-02
2
184 Views
Last Modified: 2010-04-16
Hello,

Following on from a problem related to running a php include from a mqsql database:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23862308.html#a22849649

Ahoffmann said my site contained "Ugly, very ugly code .."
and that "it's a bad idea to rerieve (php or any other) code from the database to be processed"

I would like to know what my alternatives are.

Essentially my site is comprised of Google Maps markers whose textual info is held in a database and i would like this to appear alongside photos that are held in a subfolder with the same name as the record id.

Presently i have tried to accomplish this by using the database to also hold the markup for a single image that when clicked loads all the other images from the same folder.
I ran into problems because the images are loaded by Javascript picture viewer, Highslide, and this can't read whats on the server directly so i was using PHP to do this. I included a PHP script into the database to make this idea work and that's where i ran into problems.

The Highslide forum has suggested a workaround that involves dropping the dynamic element and instead including a mini image index scipt in each folder to help load the images. (see here:)
http://highslide.com/forum/viewtopic.php?t=2600&postdays=0&postorder=asc&start=0

I would prefer to maintain a dynamic site and so i'm keen to discover how this can be done and that's where your help would be very useful - please can you explain how i might accomplish this ?


Many thanks for your ideas
0
Comment
Question by:Daniish
2 Comments
 
LVL 44

Accepted Solution

by:
scrathcyboy earned 500 total points
ID: 22862674
I hope you get lots of response to this question, because it underscores problems in PHP vs. javascript.

I think Ahoffman's dislike was embedding PHP code in a database.  What you want in the database is a set of entries that are indexed, so when you index on a pushpin, then you get (1) the text to show, (2) the thumbnail images to show, and (3) all the related links of other images to show.  This is how it should be.

The PHP code should be kept in PHP pages, and these pages do the entire assembly of all of the above, as it pulls them out of the database.  So it is the PHP code that actually puts together a complete web page for the user to see -- and part of that webpage is the javascript that runs the slide show.  

Now if you HAVE to use highslide, then you encapsulate ALL that code into a single JS file, that included in the head of the document.  Then all you need is one or two functions to start and stop the slide show, and those are merely referenced in the new Page that PHP composed and sent to the browser --

<BODY onLoad="startShow();>
Button 1 -- start slide show
Button 2 -- stop slide show.
Plus whatever other HTML in the page.

So in summary, all PHP to put the pages together in the PHP files, ALL linked data in the database, and javascript sent to the browser in the page that runs the Highslide.  I hope that helps.
0
 

Author Comment

by:Daniish
ID: 22866358
Thanks Scrathcyboy that's helpful. I will keep this question open for a while to see if anyone else has any thoughts on this because i would like to understand this better.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to make a good PHP + MySQL + JS pagination system? 3 31
PHP Mail error 3 26
Echo Multiple values from multiple records 19 40
2 separate CSS animations 2 16
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question