Skip to content

Instantly share code, notes, and snippets.

View abdullahbutt's full-sized avatar

Abdullah Butt abdullahbutt

  • Fulda, Deutschland
View GitHub Profile
@abdullahbutt
abdullahbutt / $_post.php
Last active December 25, 2015 03:58
$_post in php
<!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>
<?php
$n=10;
for($x=0,$y=1,$z,$i=0;$i<$n;$i++)
{
if($i==0)
{
echo $x."<br>".$y."<br>";
}
@abdullahbutt
abdullahbutt / mysqli_num_rows()
Created October 21, 2013 06:26
PHP mysqli_num_rows() Function
<?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";
@abdullahbutt
abdullahbutt / mysqli_query()
Created October 21, 2013 06:27
PHP mysqli_query() Function
<?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");
@abdullahbutt
abdullahbutt / mysql_connect
Created October 21, 2013 07:23
PHP mysql_connect() Function
<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
<?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";
@abdullahbutt
abdullahbutt / CI_form_dropdown
Last active December 27, 2015 22:59
CI form dropdown
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',
@abdullahbutt
abdullahbutt / CI_db_connection
Created November 10, 2013 20:03
CI db connection
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:
@abdullahbutt
abdullahbutt / CI_hyperlinks
Last active December 27, 2015 22:59
CI hyperlinks
@abdullahbutt
abdullahbutt / CI_form_prep
Created November 10, 2013 20:16
CI function form prep
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 === '')