Thursday, June 4

Notes to Self

Populating a table from csv:

  LOAD DATA LOCAL INFILE '/data.csv'
->INTO TABLE test_table
->FIELDS TERMINATED BY ','
->LINES TERMINATED BY '\r\n'
->(field1, filed2, field3);
Fields for money, use DECIMAL(N,2). N is however long the number will be and 2 is for the cents.

Then use PHP's number_format($number,2) to make it look pretty/readable.

Quick and dirty sum (via tizag):
<?php
$query = "SELECT type, SUM(price) FROM products GROUP BY type";

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "Total ". $row['type']. " = $". $row['SUM(price)'];
echo "<br />";
}
?>
Don't use & in your $_GET var. Do a str_replace to something else (no, not & amp; either), then change it back before the query

Gigundo tables will time out before loading the page

We are 2.6 parsecs from Sirius

No comments: