This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>$_Post</title> | |
<style> | |
form ul {margin:0; padding:0} | |
form li {list-style:none; margin-bottom:1em } | |
</style> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$n=10; | |
for($x=0,$y=1,$z,$i=0;$i<$n;$i++) | |
{ | |
if($i==0) | |
{ | |
echo $x."<br>".$y."<br>"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con=mysqli_connect("localhost","my_user","my_password","my_db"); | |
// Check connection | |
if (mysqli_connect_errno($con)) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con=mysqli_connect("localhost","my_user","my_password","my_db"); | |
// Check connection | |
if (mysqli_connect_errno($con)) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
// Perform queries | |
mysqli_query($con,"SELECT * FROM Persons"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysql_connect("localhost","mysql_user","mysql_pwd"); | |
if (!$con) | |
{ | |
die('Could not connect: ' . mysql_error()); | |
} | |
// some code | |
mysql_close($con); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$link = mysql_connect("localhost", "mysql_user", "mysql_password"); | |
mysql_select_db("database", $link); | |
$result = mysql_query("SELECT * FROM table1", $link); | |
$num_rows = mysql_num_rows($result); | |
echo "$num_rows Rows\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now let's imagine that you are writing a data entry form in HTML, and you want | |
a drop-down query box. Let's say this drop-down query box shows three options and allows the user to select one of them. In HTML, a drop-down box can be created like this: | |
<select name="type"> | |
<option value="1">www.this.com</option> | |
<option value="2">www.that.com</option> | |
<option value="3" selected>www.theother.com</option> | |
</select> | |
CI's version is both shorter and, because it works from an array, more adapted to PHP processing: | |
$urlarray = array( | |
'1' => 'www.this.com', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imagine you are writing a database query. This is how you might write a function within your PHP programme to query a MySQL database: | |
$connection = mysql_connect("localhost","fred","12345"); | |
mysql_select_db("websites", $connection); | |
$result = mysql_query ("SELECT * FROM sites", $connection); | |
while ($row = mysql_fetch_array($result, MYSQL_NUM)) | |
{ | |
foreach ($row as $attribute) | |
print "{$attribute[1]} "; | |
} | |
Now see how a CI function would handle a similar query: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Keep Your Links Up-To-Date Automatically | |
Imagine that you've just written a menu page, with lots of hyperlinks to other pages in your site. They are all in the traditional HTML format: | |
<a href="http://www.mysite.com/index.php/start/hello/fred">say hello to Fred</a> | |
Then, you decide to move the site to another URL. That means you have to go painstakingly through your code, looking for each URL, and re-writing it, or else none of your links will work. | |
CI gives you a simple function to write hyperlinks like this: | |
echo anchor(start/hello/fred, Say hello to Fred); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Save Database Crashes: 'prep' Your Data Entry Forms | |
Data entry is fraught with problems. Because of limitations of HTML and databases, data that contain certain symbols— for example, apostrophes and quotation marks—may cause your database to crash or to give results you did not expect. | |
The answer to this is to prepare or 'prep' your data in your data entry form, before it is submitted to the database. All this takes time and a certain amount of extra coding. | |
CI's form helper does this, automatically. So, when you create an input box by typing: | |
echo form_input('username', 'johndoe'); | |
You're also getting the hidden benefit of: | |
function form_prep($str = '') | |
{ | |
if ($str === '') |
OlderNewer