Skip to content

Instantly share code, notes, and snippets.

View umairidrees's full-sized avatar

Umair Idrees umairidrees

  • Lahore
View GitHub Profile
@umairidrees
umairidrees / show all records
Last active December 22, 2015 01:59
just copy that table. and add database table name. and all data will be available for you on your page from database.
<?php
$username="root"; $password=""; $database="exam_codes";
$con = mysql_connect("localhost",$username,$password) or die( "Unable to Connect database");
mysql_select_db($database,$con) or die( "Unable to select database");
$ShowTable = "blogs";
$sql = mysql_query("SELECT * FROM `$ShowTable` LIMIT 11");
$row = mysql_fetch_assoc($sql);
// show headings alon
<?php
if(isset($_POST['submitcsv'])){
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,"r");
while($file = fgetcsv($handle,1000, ",")){
$sql = mysql_query("INSERT INTO `table`(`value-1`, `value-2`) VALUES ('$file[0]','$file[1]')");
};
}
?>
@umairidrees
umairidrees / save as csv
Last active December 29, 2015 07:49
here I have shared an easy code for how to save data in csv format using php
$file = fopen("_file.csv","w");
foreach ($vals as $val)
{
$result = array($val[0],$val[1],$val[2]);
fputcsv($file,$result);
}
fclose($file);
<?php
$username="root"; $password=""; $database="exam_codes";
$con = mysql_connect("localhost",$username,$password) or die( "Unable to Connect database");
mysql_select_db($database,$con) or die( "Unable to select database");
// Table Name that you want
// to export in csv
$ShowTable = "blogs";
$FileName = "_export.csv";
$file = fopen($FileName,"w");