Monday, February 28, 2011

how to make chat on php ?

how to read csv file and display its field values on a web page. Complete PHP source code is provided.
Download filetoread.csv file with tab delemited fields. For simplicity the file has only six fields and five records. Create datafeed derictory in your web site root directory and save filetoread.csv file in datafeed directory. Look at the file records.
the PHP file with source code, which reads the csv file is explained below
');
print('Computer electronics');
print('PartnumberProductCompany
LinkPrice');
//declare variable to count records
$rowcount = 0;
//get path to file assumming that file located in datafeed folder
$path_to_file="datafeed/filetoread.csv";
//open file for reading "r"
$handle = fopen($path_to_file, "r");
//read file line by line
while (($record = fgetcsv($handle, 1000, " ")) !== FALSE)
{
// read number of fields in one record
$numfields = count($record);
//Display all fields for debugging, to know which data is in which field.
//In real scv datafeed file of an affiliated program a lot of fields are stored
//data, that you do not need. Using output below you can see what fields to select
//to build your advertisement on your web page

for($i=0; $i<$numfields; $i++) { echo $i.":".$record[$i]."
";
}

//read field values in variable
$part=$record[0];
$number=$record[1];
$product=$record[2];
$company=$record[3];
$clicklink=$record[4];
$price=$record[5];
//skip the first record since it has field headers only
if($rowcount > 0)
{
//if record has link to item display it in the table row
if($record[3] !="")
{
print(''.$part.''.$number.''.$product.'
'.$company.'
'.$product.''.$price.'');
}
}
$rowcount++;
}
fclose($handle);
print('');
?>
Download readcsv.txt file and save it as .php file in your web site root directory.
Download filetoread.csv file with tab delemited fields.
Remove txt extension after downloading files.
In a web page you want to display records from csv file type:

We are done.

No comments:

Post a Comment