Category Archives: MySql

PHP / MySql – Export Data to Excel

A PHP Script to export MySql data to Excel.



$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

PHP : Create array from MySql recordset

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

$sel=”SELECT * FROM table_name”;
while ($row = mysql_fetch_assoc($rs))
$array[$i] = $row;

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 = P.parent_id),''), if(parent_id > 0,'-',''), display_order ) AS new_col FROM `table_a` P order by new_col