• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP help!

Shimmishim

Elite Member
my index.php makes calls to a bunch of other php files....

<?php
include "connect.php";
include "user_get_info.php";
include "functions.php";

echo "<link rel='stylesheet' href='weblog.css' type='text/css'>";

include "menu_top.php";

if (isset ($error)) {
include "error.php";
}

elseif (isset ($weblog)) {
if ($weblog == 'item_add') {
include "weblog_item_add.php";
}

elseif ($weblog == 'item_edit') {
include "weblog_item_edit.php";
}

elseif ($weblog == 'item_delete') {
include "weblog_item_delete.php";
}

elseif ($weblog == 'item_submit') {
include "weblog_item_submit.php";
}

elseif ($weblog == 'item_review') {
include "weblog_item_review.php";
}

elseif ($weblog == 'reaction_edit') {
include "weblog_reaction_edit.php";
}

elseif ($weblog == 'reaction_delete') {
include "weblog_reaction_delete.php";
}

elseif ($weblog == 'archive') {
include "weblog_archive.php";
}

elseif ($weblog == 'search') {
include "weblog_search.php";
}

else {
include "weblog_item_display.php";
}
}

elseif (isset ($user)) {
if ($user == 'register') {
include "user_register.php";
}

elseif ($user == 'pm') {
include "user_pm.php";
}

elseif ($user == 'overview') {
include "user_overview.php";
}

elseif ($user == 'admin') {
include "user_admin.php";
}

elseif ($user == 'poll') {
include "user_poll.php";
}
}

else {
include "weblog_default.php";
}

include "menu_right.php";

echo "<div id='banner'>
</div>";
?>



that's what it looks like...

now i found a site taht generates html codes to use to play music in the background..

i was wondering how i could stick this into my index.php to get it to play the music or would i have to generate a new file like music.php in order to play the music...

here is the generated code anyway:


(soundFile.indexOf(",") > 0) {var sounds = soundFile.split(",");soundFile = sounds[Math.floor(Math.random()*sounds.length)];}if(navigator.plugins.length>0){
if (navigator.mimeTypes["audio/mp3"] && navigator.mimeTypes["audio/mp3"].enabledPlugin) document.write('<embed src="'+soundFile+'" autostart="true" loop="true" controls="LargeConsole" width=145 height=35></embed>');}
else {
document.write('<embed src="'+soundFile+'" autostart="true" loop="true" width=70 height=45></embed>');}

//-->
</script>
<noscript><embed src="http://(this is where the link goes)" autostart="true" loop="true"></embed></noscript>
<noembed><bgsound src="http://(this is where the link goes)" loop=true></noembed>




thanks for the help!
 
That's javascript and html, just stick it in your page. And.. the rest of the php is waaaayyy overdone. You could accomplish all of that in like 15 lines.
 
where though?

yeah it's another script i got from somewhere else...

it's minimal upkeep really...

anyway

i tried inserting it before the php part and after and inbetween and i dunno where to put it 🙁
 
Check out the javascript tutorial on w3schools.com, maybe that will clear it up more for you.

And as for cleaning up the code...

Instead of

if($this == "that")
include "blah_blah_that.php";

just make a list of all of the things that could be in "blah_blah_*.php" and then check if the value is in that list, then if so, stick the string in there.

for example, instead of :

if ($weblog == 'reaction_delete') {
include "weblog_reaction_delete.php";
}

elseif ($weblog == 'archive') {
include "weblog_archive.php";
}

Do:

if(in_array($weblog, array("reaction_delete", "archive")))
include "weblog_$weblog.php";

The basic idea is that you can put a lot of logic into data, i.e. instead of having if elseif elseif elseif elseif elseif else, with data interspersed in there, just make some lists of the data you want to look at, then search the list or loop through it. Generally I find that seperating data and logic makes things a lot cleaner.

And you don't need braces for single statements, so you can ditch almost all of those braces.
 
Back
Top