Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 7 of 7

Thread: PHP Sturcture ?

  1. #1
    Join Date
    May 2006
    Posts
    5,380

    PHP Sturcture ?

    Hi All

    Im working on my site (again), i almost got it finished than changed my mind on the structure of the PHP, i was echoing each line of html from within the php file, didn't like it, was unmanageable!!

    so i opted to use raw html and insert <?php ?> where i want some scripting done

    is this a recommend way, if not, what the h3ll is ?

    PHP Code:
    <!-- start page -->
    <div id='page'>

        <!-- start content -->
        <div id='content'>
            
            <?php 
                $Query
    =mysql_query("SELECT * FROM Plugins WHERE ID=".$ID);
                if (
    $Query<>false)
                {    
                    while(
    $Row mysql_fetch_array($Query))
                    {
                    
    ?>
                        <div class='post'>
                            <h2 class='title'><?php echo($Row["PluginName"]); ?></h2>
                            <div class='entry'>
                                <p><?php echo("<b>Version:</b> ".$Row["Version"]."<br/><b>ReleaseDate:</b> ".$Row["ReleaseDate"]."<br/><b>LastUpdate:</b> ".$Row["LastUpdate"]."<br/><b>Author:</b> ".$Row["Author"]."<br/><b>Licence:</b> ".$Row["Licence"]."<br/>");?></p>
                                <p><?php echo($Row["LongDesc"]);?></p>
                                <p><?php echo("<b>Requirements:</b> ".$Row["Requirements"]."<br/><b>Installation:</b> ".$Row["Installation"]);?></p>
                            </div>
                            
                            <div class='meta'>
                                <p class='byline'><?php echo("Views: (".$Row["Views"].")  Downloads: (".$Row["Downloads"].")"); ?></p>
                                <p class='links'><a href='news.php?ID=<?php echo($Row["ID"]);?>' class='more'>Read full article</a> <b>|</b> <a href='#' class='download'>Download</a></p>
                            </div>
                        </div>
                    <?php
                    
    }
                }
            
    ?>

        </div>
        <!-- end content -->
        
        <?php 
            
    include("sidebar.php");
        
    ?>
        
        <div style='clear: both;'>&nbsp;</div>
    </div>
    <!-- end page -->
    Open your eyes to Narcissism, Don't let her destroy your life!!

  2. #2
    Join Date
    May 2006
    Posts
    5,380
    Ermm, Hello ...


    C'mon Guys, This isn't the Krypton Factor, a simple "Yes" or "No" would suffice!!
    Open your eyes to Narcissism, Don't let her destroy your life!!

  3. #3
    Join Date
    May 2006
    Posts
    5,380
    Agrrrr.... im going mad here trying to get my javascript to work from php generated html.....

    You ever have those times when you ask your self "Why on earth did i start this"!

    This is like trying to learn French, Spanish and German all at the same time, how the h3ll do you web devs do it??

    heres what i want to do, i have a javascript function that i want called from a html hyperlink "OnClick" event and return false if the user does not confirm and true if he does and follow the link

    my javascript
    Code:
    function Confirm_Delete_Plugin()
    {
    	
    	var answer = confirm("Are sure you want to delete this plugin.")
    	if (answer)
    	{ 
    		
    		return false ; 
    	}
    	else 
    	{ 
    		return true ;
    	}
    }
    my html (and php)
    PHP Code:
    <a href='deleteplugin.php?Type=<?php echo($Row["PluginType"]);?>&ID=<?php echo($Row["ID"]);?>' onClick='return Confirm_Delete_Plugin()'; class='more'>Delete</a>
    from all the information i can find, this seems the correct way to do it, but i just cant get it to work, it just follows the link address no matter what i do

    i can get this system to work from a form button, but not from a link....Please...HELP!!!!, lol
    Open your eyes to Narcissism, Don't let her destroy your life!!

  4. #4
    Join Date
    May 2006
    Posts
    5,380
    Cheers, thanks for the tips guys

    I found out why it didn't work, my dam browser cached the .js file so when i added the function the stupid browser could not see it, only found that out by accident while trying to validate an email address!

    I don't need no dam help!!
    Open your eyes to Narcissism, Don't let her destroy your life!!

  5. #5
    Join Date
    Oct 2004
    Location
    East, South & West Asia
    Posts
    1,020
    Hi Riz,

    So you solved your problem by thinking aloud in IR forum... eh? I should be doing the same way to solve my issues. lol.

    I make this belated respond a long one, so you can divide them among your unanswered posts. ROFLMAO !!

    About the preferred methods of whether:
    1. HTML echo'ed by PHP or
    2. PHP wrapped around HTML.

    Here are some rationale:
    >I use both according to HOW READABLE THE WHOLE PAGE CODE will look like.

    >In terms of page economy ( so it will load faster ), I will wrap the PHP codes around HTML.

    >In terms of convenience ( for later replications ), I will wrap PHP codes around HTML.

    >When echo-ing HTML, you're putting lots double or single quotes. This will mess up my logic sometitmes. In the end, something which is so easy becomes difficult.

    >In my experience, my apps run faster with HTML as the template. Probably because Apache Web Server looks for HTML first, then the rest.

    >The last rationale why I wrap PHP around HTNL is that, it would be easier for me to change the Server Side App language whenever there is a need to do so. I might want to change PHP to TOMCAT, Java, J,K, D or even LUA.

    At times, we do need to REQUIRE or INCLUDE, I still wrap PHP codes around HTML in those snippets.

    As far as I remember, the only significant time to echo HTML is when I use SWITCH or location REDIRECT or LOOPS. Other than that, HTML will be the frame.

    This little bit of knowledge comes from experience making custom CMS some years back for a fairly large NGO, a Travel Agency and a Housing Developer. Not because I wanted to but because ready-made CMS in the market cannot cater for their needs.

    NOTE:
    PHP is far easier than LUA but LUA is the fastest in terms of processing of all languages.
    Newbie Examples
    ------> AMS 7.5 : amstudio.azman.info
    ----> AMS 6 & 5: www.azman.info/ams/
    ----> FB: facebook.com/GuideToWealth

    ----> Content Development Blog: www.AZMAN.asia

  6. #6
    Join Date
    May 2006
    Posts
    5,380
    Ha Yes, thinking aloud solved my problems

    after 2 or 3 attempts at the site i went with the template system with just basic loops and conditions in the html pages and cut the use of "echo" to a bare minimum, and some backend modules for the more complex php stuff, this seemed to be the general advice on the web, so after pulling most of my hair out i finally got a working system that seems pretty robust (im all my tests)

    im really enjoying working with PHP, iv done some things with my site i never thought i would be able to get done on my own, progress is slow because of my work life, but its getter there

    Thanks for the tips, i pretty much built the site to the same spec
    Open your eyes to Narcissism, Don't let her destroy your life!!

  7. #7
    Join Date
    Oct 2004
    Location
    East, South & West Asia
    Posts
    1,020
    Hi,

    Sorry for confusion.

    What I mean by "have PHP code wrapped around HTML" is actually, having PHP codes nested within HTML.

    It means, HTML is the template.
    Newbie Examples
    ------> AMS 7.5 : amstudio.azman.info
    ----> AMS 6 & 5: www.azman.info/ams/
    ----> FB: facebook.com/GuideToWealth

    ----> Content Development Blog: www.AZMAN.asia

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts