Tag Archives: database

PHP / MySql – Export Data to Excel

A PHP Script to export MySql data to Excel.


<!--?php
$content=””;

if($_REQUEST[‘export’])
{


$select= "select user_id,email,fname,lname,bdate,fees from user order by fname";
$result = mysql_query($select);
$num_row = mysql_num_rows($result);
Continue reading

Advertisements

PHP : Create array from MySql recordset

This PHP code is to create array from MySql record set.

<?php
$sel=”SELECT * FROM table_name”;
$rs=mysql_query($sel);
$i=0;
while ($row = mysql_fetch_assoc($rs))
{
$array[$i] = $row;
$i++;
}
?>

MySql – Convert numeric field to string field in select statement


SELECT cast( numeric_field AS char ) FROM table_name

MySql – Conditional display order

This is the select statement in MySql to get records in order with parent and child view.

 

SELECT *, CONCAT( if(parent_id > 0,(select display_order from `table_a` C where C.id = P.parent_id),''), if(parent_id > 0,'-',''), display_order ) AS new_col FROM `table_a` P order by new_col