So, I have some code and am wondering what would make my site faster, loading it from the database, or just adding an include function....
what is the nature of the content? dynamic or once written is gonna be same way forever? how frequent new content come? at what frequency would you need to change it? and does it have to be done by someone not knowing php? above questions when answered properly, will give solution automatically
nature: javascript functions stored in php files dynamic: no, always same code in a specific file frequency of new content: n/a frequency of display: one file will display every 1 out of 10 times from a list of 10 files in a loop do i know php?: yes
i would suggest include only, that since they are not gonna change frequently, store them as JS and get cached to reduce your data transfer resulting in faster page load
I think (hope) the OP's asking whether he should store info in an array rather than fetching it from the database.
I disagree. I use a database to store Smarty templates and PHP code (smarty resource) and it works great.
@kbluhm - basically @killaklown - unless you have over 1000 embedded videos that sometimes have to be changed, although I agree that large static code should not since it wastes more bandwidth
i dont get the 'unless you have over 1000 embedded videos that sometimes have to be changed'. The table should store url, width, height... shouldnt need to have the code for the embedded video in it... (unless im mis-understanding what your saying) @nihcer, im not saying its wouldnt work, databases are meant to store.. data... not source code. Sure you can, but its not suggested that you do.
I think you are misunderstanding me killaklown. Picture this: a movie site with embedded videos from megavideo, youtube, veoh, and zshare. Now, each one has its own style of code. Like zshare - it uses an iframe, while youtube uses an object. My theory behind this is that it's more efficient if the entire embed code is stored in the database, instead of having a function for each site to get the URL, then get the video from the site. Or, how you're saying(if i understand correctly) that the table has a column for width, height, url, ect. This is fine, but very tedious, unless you have a script that picks out the variables from the embed code for each type of code. Therefore, you just copy and paste the code, and echo it onto the page...and voila, you have a motion picture. So, whenever the video goes missing (if it's deleted), then you just go use the video host's search engine to find the same video from another user.
I would think functions would work fine... (Pseudocode) if(video==youtube) embedYoutube(url,width,height); else if(video==zshare) emebedZshare(url,width,height); Code (markup): Much less traffic between application and database if you use functions. Sure, your way is a quick and easy way, and it achieves the same result... but a professional developer would never say to do it that way. (unless if they really dont care about moniterizing... which really wouldnt make them a professional then) Edit: also possible to copy & paste embedded code into a textbox, and have the php pull out the width/height/url
hmm, looks like I better take notes lol quick question: I have a piece of code where, $n is a sequential number from 1-20, and $display is from the database with numbers 1-20, but in a random order. How can the following code be edited so that $display will equal $n? $n = 0; while ($n < 20) { $n++; $query_d = "SELECT display FROM hits_d WHERE id='$n' ORDER BY display DESC"; $result_d = mysql_query($query_d) or die('Sorry, could not access the database'); $row_d=mysql_fetch_array($result_d, MYSQL_BOTH); $display = $row_d['display']; $a = '$a'."$n"; if ($display == $n) {$show = $a;} echo "n: $n display: $display show: $show<br/>"; } PHP: