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
181 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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 26
advertisement module in core php 4 81
php namespace question with Twilio 4 15
Help cleaning out CSS 2 23
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now