connect with database in php with mysql
<?php
$host='localhost';
$user_name='rootgf';
$password='';
@$con = mysql_connect("$host","$user_name","$password");
if ($con)
{echo '<br>host coonected<br>';}
else
{
die('Could not connect ');
}
?>
connection.php :
<?php
require 'connection.inc.php';
mysql_close($con);
?>
run " connection.php"
output :
host coonected
array
arrays display
associative arrays in php
multi dimensional arrays in php
for each statements with arrays in php
add one arry to another array or append
array reduce with array_splice() in php
array to string in php
change array size using array_pad() in php
delete array elements with unset() in php
check array index or key with user inputs in php
checking if an element is in array or not using in php
Send text and lenth to output for HTML
<?
function SafGetDoneBodyText($mytext,$after=0,$mytextlenth=0) { // send text and replace chr13 with br and number of text
$mytext = stripslashes($mytext);
if ($mytextlenth) {
$mytext = substr($mytext,0,$mytextlenth);
}
$mytext = str_replace(chr(13),"<br>",$mytext);
$mytext = str_replace("\n","",$mytext);
return $mytext;
}
?>
Quiz #1 Finished
I took the Quiz #1, but the result is not that good.
PHP Security by Example
Almost an entire month has passed since my last blog entry, and a lot has happened. I'll try to catch up over the next week or two.
About a week ago, the Flash version of PHP Security by Example was Dugg.
I'm always disappointed to see trolls (Digg seems to have a bigger problem with this than Slashdot), but a few of the comments raise some valid questions. I'll try to summarize and answer those here.
It's true that slides are never a substitute for a talk, and this is especially true for this one, because it's a hands-on workshop. It's something Marco calls a BYOL (bring your own laptop), and it involves a lot of one-on-one attention and hand-holding.
The reason it's in Flash is because the person submitting the story linked to the Flash version. :-) To be fair, the only other format available for this talk is PDF. I've been wanting to create a nice web application for viewing Keynote slides. I think the best approach might be to export the slides as images, and create a simple slide navigator. I can always continue to also offer PDF, Quicktime, and Flash formats.
php arrays
Array: An array is a variable,which can store multiple values in a single variable with same data type. A data type may be number or string or any data type.
In PHP, there are three kind of arrays:
Numeric array - An array with a numeric index
Associative array - An array where each ID key is associated with a value
Multidimensional array - An array containing one or more arrays
1) Numeric arrary example:
<?php
$course=Array("php","java","dotnet","C++");
echo "$course[0]<br/>";
echo "$course[1]<br/>";
echo "$course[2]<br/>";
echo "$course[3]<br/>";
?>
Out Put:
php
java
dotnet
C++
<?php
$course=array("java"=>jsp,"dotnet"=>asp,"c++"=>oops);
echo "java is basic for" .$course['java']."learning<br/>";
foreach($course as $cat=>$dept)
{
echo $cat."=>".$dept;
echo "<br/>"; }
?>
?>
java is basic forjsplearning
java=>jsp
dotnet=>asp
c++=>oops
$books = array(
array('Engineering','Civil', 'ComputerScience','Mechanical'),
array('Management','Hospitality','HumanResource','Quality'),
);?>
<table border="1"><tr>
<th>Category Name</th>
<th>Dept-1</th>
<th>Dept-2</th>
<th>Dept-3</th> </tr>
<?php
foreach($books as $cat){
echo '<tr>';
foreach($cat as $dept) {
echo "<td>$dept</td>"; }
echo '</tr>';}
?>
Out put:
| Category Name | Dept-1 | Dept-2 | Dept-3 |
|---|---|---|---|
| Engineering | Civil | ComputerScience | Mechanical |
| Management | Hospitality | HumanResource | Quality |