$var = $value; // ok
$var = "$value"; // ok, but double quotes are not necessary
$var = '$value'; // will not work (single quotes will not allow parsing)
('.' the period adds/connects variables, functions, etc. together.
Oftentimes programmers will leave spaces around the ' . ' to make
things easier to read.)
$var = 'This is the ' . $value . ' of things.'; // ok - preferred
technique
$var = "This is the $value of things."; // ok, but harder to read/debug
$var = 'This is the $value of things.'; // will not parse $value
$var = This is the $value of things.; // error
$var = $array['name']; // ok, generally the preferred technique
$var = $array["name"]; // ok, but why use double quotes if they are not
necessary?
$var = "$array[name]"; // ok, but harder to read/debug - poor coding
style
$var = 'Name: ' . $array['name']; // ok - preferred technique
$var = "Name: $array[name]"; // ok, but harder to read/debug - poor
coding style
$var = "Name: $array["name"]"; // error
$var = "Name: $array['name']"; // error
exampleFunction($value); // ok
exampleFunction("$value"); // ok, but double quotes are not necessary
exampleFunction('$value'); // will not parse $value
$line = $result['name'] . ' ' . $result['last_name']; // ok - easy to
read/debug
$line = $result["name"] . ' ' . $result["last_name"]; // ok, but why
use double quotes if they are not necessary?
$line = "$result[name] $result[last_name]"; // ok - but much harder to
read/debug - poor coding style
$line = $result['name'] . ' ' . doSomething($result['last_name']); //
ok - preferred method (using a function)
if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
function safeQuery($query='')
{
global $db;
if (!$query) return false;
return mysql_query($query, $db->link);
}
// returns an array of records
function fetchArray($query='')
{
if ($result = safeQuery($query)) {
if (mysql_num_rows($result) > 0) {
while ($arr = mysql_fetch_assoc($result)) $rows[] = $arr;
return $rows;
}
}
return false;
}
// returns a single record
function fetchRecord($query='')
{
if ($row = safeQuery($query)) {
if (mysql_num_rows($row) > 0) {
return mysql_fetch_assoc($row);
}
}
return false;
}
$results = fetchArray("SELECT id,field1 FROM records");
// sample output results
if (!$results) {
echo 'No results.';
} else {
// loop the data
foreach ($results as $result) {
echo $result['id'] . ' ' . $result['field1'];
}
}
class DB {
function DB() {
$this->host = "localhost"; // your host
$this->db = "myDatabase"; // your database
$this->user = "root"; // your username
$this->pass = "mysql"; // your password
$this->link = mysql_connect($this->host, $this->user,
$this->pass);
mysql_select_db($this->db);
}
}
// calls it to action
$db = new $DB;
$result = mysql_query("SELECT * FROM table ORDER BY id ASC LIMIT 0,10");
function magicQuotes($post) {
if (get_magic_quotes_gpc()) {
if (is_array($post) {
return array_map('stripslashes',$post);
} else {
return stripslashes($post);
}
} else {
return; // magic quotes are not ON so we do nothing
}
}
function escapeString($post) {
if (phpversion() >= '4.3.0') {
return array_map('mysql_real_escape_string',$post);
} else {
return array_map('mysql_escape_string',$post);
}
}
error_reporting(E_ALL);
print_r($result); exit;
if ($rs['prefix'] == 1) {
$prfx = 'Mrs. ';
} elseif ($rs['prefix'] == 2) {
$prfx = 'Ms. ';
} else {
$prfx = 'Mr. ';
}
echo $prfx.$rs['name'].' '.$rs['last_name'];
function makePrefix($prefix='')
{
if (!$prefix) return '';
if ($prefix == 1) return 'Mrs. ';
if ($prefix == 2) return 'Ms. ';
if ($prefix == 3) return 'Mr. ';
}
echo makePrefix($rs['prefix']) . $rs['name'] . ' ' . $rs['last_name'];
<head>
<title><title>
<style type="text/css">
CSS Content Goes Here
</style>
</head>
<body>
<link rel="stylesheet" type="text/css" href="Path To stylesheet.css" />
Or you can also use the @import method as shown below
<style type="text/css">@import url(Path To stylesheet.css)</style>
Either of these methods are achieved by placing one or the other in the head section as shown in example below.
<head>
<title><title>
<link rel="stylesheet" type="text/css"href="style.css" />
</head>
<body>
or
<head>
<title><title>
<style type="text/css"> @import url(Path To stylesheet.css) </style>
</head>
<body>
Are you getting the idea? It's really cool.
<p style="color: #ff0000;">Some red text</p>
Some red text
www.flickr.com
|