I'm sure code indentation is a basic requirement for correct development. I have checked out may pages to learn more and results of my coding are below.

I like to share that here to receive opinions and suggestions.

include_once "../../config.php";

// Start
if (!isset($_SESSION)) session_start();
$level = 2;

if (!isset($_SESSION['user_id']) OR ($_SESSION['user_levell'] > $req_level)) {
    header("Location: $url/dashboard.php?error=1"); exit;

// Load permissions
$result = mysql_query("
    SELECT conf
    FROM adm_users
    WHERE user_id=".$_SESSION['user_id']
$row = mysql_fetch_array($result, MYSQL_BOTH);
    $access = $row['acess'];

if (($_SESSION['user_level'] != "1") && ($access_config != "1")) {
    header("Location: index.php?error=1"); exit;
// End

include_once "$url/includes/head.php";
include_once "$url/includes/menu.php";

// Load ser
$result = mysql_query("
    SELECT  *
    FROM    adm_ser
    WHERE   ser_id='$ser_id'

$row = mysql_fetch_array($result, MYSQL_BOTH);
    $ser_id = stripslashes($row['ser_id']);
    $ser_cod = stripslashes($row['ser_cod']);       
    $ser_cd = stripslashes($row['ser_cnpj']);
    $ser_name = stripslashes($row['ser_name']);
    $ser_status_id = stripslashes($row['ser_status_id']);

// Dropdown Ser Status
$sql2 = mysql_query("
    SELECT *
    FROM adm_ser_status
    WHERE status_id=".$ser_status_id

while($row = mysql_fetch_array($sql2)) {
    $status_id_dropdown = $row['status_id'];
    $status_de_dropdown = $row['status_desc'];
  • \$\begingroup\$ There is no One True Coding Style. Decide on something and, most importantly, stick to it. (So far, everything look sensible, but I prefer to align the = of related assignments) \$\endgroup\$ – amon Mar 22 '13 at 2:05
  • \$\begingroup\$ I think your coding style is ok, also bearing in mind what Jon said. However, if you are looking to set yourself a style to stick to, I suggest PSR-2, which is adopted by Zend, Symfony, Amazon to name a few \$\endgroup\$ – Adam-E Mar 22 '13 at 23:25

You don't need to indent your $ser_ value assignments. Indentation should be left for within a class, method, loop, etc as you do for most of your other code. I notice that you separate your MySQL statement, which can be done, but on such a simple query, really isn't needed as the only purpose for doing that is to help readability when it is a complicated query. ^^

On a side note, mysql_ functions are deprecated now, and you should switch to mysqli_ (or the MySQLi class), or (preferably) PDO.

| improve this answer | |

In my opinion, it's highly recommend to use one one off "official" coding standars like

I highly recommend to use PSR-1, PSR-2.

If you want to check what codding style "errors" you have - use php code sniffer:

| improve this answer | |
  • \$\begingroup\$ agree. Adoption much better than invention. \$\endgroup\$ – Rob Apodaca Mar 31 '13 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.