Let say you have a table called students with two fields fname and age.
insert into students (fname, age) values
('Kusal', '26'),
('Tom', '18'),
('Ann', '23')
Remember to give the column names in the query.
insert into students (fname, age) values
('Kusal', '26'),
('Tom', '18'),
('Ann', '23')
$result = mysql_query("select count(id) from table");
$data = mysql_fetch_array($result);
$all_rows = $data[0];
$result = mysql_query("select id from table");
$all_rows = mysql_num_rows($result);
<?php
$array = array ("Fruit" => "Apple", "Animal" => "Dog", "Number" => 1, "Name" => "Jhon" );
foreach($array as $key => $value)
{
echo $key.': '.$value;
echo '<br />';
}
/* result
Fruit: Apple
Animal: Dog
Number: 1
Name: Jhon
*/
?>
<?php
$str = 'Hello World';
echo strlen($str); // 11
?>
<?PHP
echo '<pre>';
print_r(gd_info());
echo '</pre>';
?>
<?PHP
//save the arial.ttf font file in the same folder
$font = 'arial.ttf';
$fontsize = 10;
$YourText = 'Hi This Work';
$Text_Box = imagettfbbox($fontsize, 0, $font, $YourText);
//create image width 250, height 100
$image = imagecreatetruecolor(250,100);
//0,0,0 is black
$bgcolor = imagecolorallocate($image, 0, 0, 0);
//255, 255, 255 is white
$fontcolor = imagecolorallocate($image, 255, 255, 255);
//create a rectangle with the back ground coloe
imagefilledrectangle($image, 0, 0, 250, 100, $bgcolor);
$x = 10;
$y = 20;
//draw text on image
imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $YourText);
//setting png headers
header('Content-type: image/png');
//create png image
imagepng($image);
//delete tempory files
imagedestroy($image);
?>
<img src="your_file_name.php" />
<?php
$my_array = array('1', 'kuppiya', 'Tom', 'Hello');
$key = array_search('Tom', $my_array);
if($key === false)
{
echo 'Not found';
}
else
{
echo $my_array[$key];
}
?>
<?php
error_reporting(E_ALL);
echo $name= $_POST["name"];
echo $number= $_POST["number"];
?>
<html>
<body>
<form name="form1" method="POST" action="">
<table border="0">
<tr>
<td>Name :</td>
<td> <input type="text" name="name" /></td>
</tr>
<tr>
<td>Tel: Number :</td>
<td> <input type="text" name="number" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="sub" value="Add" /></td>
</tr>
</table>
</form>
</body>
</html>
if(isset($_POST['sub']))
{
echo $name= $_POST["name"];
echo $number= $_POST["number"];
}
<?php
echo sqrt(4); // 2
echo sqrt(12); // 3.4641016151378
echo sqrt(16); // 4
echo sqrt(17); // 4.1231056256177
?>
<?php
echo round(10.8); // 11
echo '<br />';
echo round(10.4); // 10
echo '<br />';
/*you can also set the number of precision,
or in other words number of decimal digits
you like to round the floating number
*/
echo round(10.837, 2); // 10.84
echo '<br />';
echo round(10.435767, 4); // 10.4358
echo '<br />';
?>
<?php
$dir_path = 'kusal/test'; //directory path
$list_files = scandir($dir_path);
//dumping the array
//hope you know how to access an array
echo '<pre>'; //html <pre> tags will format the output
print_r($list_files);
echo '</pre>';
/*
Output look like this
Array
(
[0] => .
[1] => ..
[2] => TextDocument.txt
[3] => kuppiya.doc
[4] => lion.ppt
[5] => test.as
)
*/
?>
<?php
$path = 'path to directory'
//First Check if deleting a directory
if(is_dir($path))
{
//remove directory
if(rmdir($path))
{
echo 'Deleted';
}
else
{
echo 'error';
}
}
else
{
echo 'Not a directory';
}
?>
<?php
$my_string = "This STRING has UPPERCASE letters";
$my_string = strtolower($my_string);
echo $my_string;
//Output: this string has uppercase letters
?>
<?php
//checkdate($month, $day, $year) - format
$month = 10;
$day = 12;
$year = 2008;
echo 'Valid Date Example: ';
if(checkdate($month, $day, $year))
{
echo 'Date is correct';
}
else
{
echo 'Date is incorrect';
}
echo '<br /><br />';
echo 'Invalid Date Example: ';
//Invalid date
$month = 14; // month is wrong
$day = 12;
$year = 2008;
if(checkdate($month, $day, $year))
{
echo 'Date is correct';
}
else
{
echo 'Date is incorrect';
}
?>
<?php
$array_items = array('item1', 'item2', 'item3');
$string_with_comma = implode(",", $array_items);
echo $string_with_comma; // item1,item2,item13
?>