# Better code indentation

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.

<?php
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'];
}
?>

• 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) – amon Mar 22 '13 at 2:05
• 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 – Adam-E Mar 22 '13 at 23:25

## 2 Answers

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.

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:

• agree. Adoption much better than invention. – Rob Apodaca Mar 31 '13 at 17:31