Forum Moderators: coopster

Message Too Old, No Replies

Any help for newbie

Help (Best Practice cosing style)

         

Finish3r

4:44 am on Oct 7, 2010 (gmt 0)

10+ Year Member



Hello to all webmaster i am John, i am a newly web programmer i just want to ask for help because i am really confused with my coding style.

could any one can give me some tutorial or example of best practice coding style..

i am developing now my first live project this is the link [url]coceans.kagayan.org[/url]

please give me some good advice to become a good php programmer


Thanks you so much. :)
God Bless

screen name: Finish3r

Anyango

7:21 pm on Oct 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Finish3r,

Welcome to WebmasterWorld. You will find many good resources and good people here to guide you. To start with, would you like to share what all you know about it ? and what are you confused about in your coding style?

Matthew1980

8:06 pm on Oct 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



^^^

Well said, I found this place to be an excellent resource when I started out, but it was years before I decided to join in with the fun!

Yep, just show us all an example of what you have, then the erudite people here can guide you in your quest!

Cheers,
MRb

Finish3r

12:45 am on Oct 8, 2010 (gmt 0)

10+ Year Member



@Matthew1980: Thanks you so much sir :D.
@Anyango : i just wondering if what would be the best coding style building a website, because i just want to put all my code in my index.php.

For example:
I have register.php, about.php, login.ph and etc.... is't possible by calling and view them in my index.php?. my friend told me that i need to used function in that case and have a return value.


My Example Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<?php include_once "errorreporting.inc.php"; ?>
<?php include_once "inc.module.php"; ?>
<?php include_once "tittle.inc.php"; ?>
<?php include_once "head.inc.php"; ?>

<body>

<div class="forbg"></div>
<div class="forbeta"></div>

<div class="container">

<div class="header"></div>
<div class="spacer1"></div>
<?php include_once "nav.inc.php"; ?>
<div class="spacer1"></div>

<div class="main">

<div class="leftBContainer">

<?php
include_once "login.inc.php";
include_once "newestmember.inc.php";
include_once "stats.inc.php";
include_once "violators.inc.php";
?>

</div>

<div class="centerBContainer">

<?php
switch(isset($_GET['page'])) {

case "register":
echo loadRegister();
break;

default:
include_once "welcomemsg.inc.php";
include_once "announcement.inc.php";
include_once "member.inc.php";
break;
}
?>

</div>

<div class="rightBContainer">
<?php

include_once "whosonline.inc.php";
include_once "weatherforecast.inc.php";
include_once "relatedlinks.inc.php";
?>
</div>

<div class="spacer"></div>

</div>

<?php include_once "footer.inc.php"; ?>

</div>

</body>

</html>

Anyango

5:48 pm on Oct 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[webmasterworld.com...]

check last 2 posts with code, they will give the basic of how you can have multiple pages being loaded from 1 single file. then you can modify the basic idea to your needs and build on it

Finish3r

6:00 am on Oct 10, 2010 (gmt 0)

10+ Year Member



Thanks sir :D

paperso

6:14 am on Oct 10, 2010 (gmt 0)

10+ Year Member



@Finish3r! Welcome!

Since you've ask for examples, it's here:

You can always create a php file (global) that holds different php files.

Check below code. So if you have index.php, you just have to include this one file.

init.php
include('includes/config.php');
include('includes/mysql.php');
include('includes/inc.module.php');



You uses a lot of includes. Sometimes it's better to use function.

whosonline.inc.php
function whosOnline()
{
// run here
}

Finish3r

6:29 am on Oct 10, 2010 (gmt 0)

10+ Year Member



Wew @Paperso :D sir thank you so much you gave me great idea... thank you.. i'll try that one. :)

paperso

8:10 am on Oct 10, 2010 (gmt 0)

10+ Year Member



@Finish3r

Works great specially if you have other directory like admin/ \(^_^)/