Random Snippets

  • Home
  • Sequence analysis blog
  • About
  • Categories
    • javascript
    • mysql
    • php
  • Subscribe via RSS

php

Sorting 2D associative arrays in PHP

July 13th, 2009  |  by Knix  |  published in php

Surprisingly, it took me a long time to find this solution so I decided to post it for anyone who had a situation similar to mine.
Let’s say you have the following 2D associative array in PHP of fruits and their corresponding prices and you want to have them sorted by price:

$fruits = array
(
[...]

How to convert MySQL timestamp to PHP date type

October 5th, 2008  |  by Knix  |  published in mysql, php

Let’s say you have the following PHP code that extracts the date from the times table in your MySQL database. The date is of timestamp type which has the following format: ‘YYYY-MM-DD HH:MM:SS’ or ‘2008-10-05 21:34:02.’

1
2
3
4
$res = mysql_query("SELECT date FROM times;");
while ( $row = mysql_fetch_array($res) ) {
echo $row[’date’] . "<br />";
}

Recent Posts

  • Sorting 2D associative arrays in PHP
  • Dynamic or on-the-fly percentage calculations with JavaScript
  • The dangers of embedding the notorious “void(0)” JavaScript code in the href attribute of the “a” tag
  • How to randomly order or select rows in a MySQL query
  • How to convert MySQL timestamp to PHP date type

Recent Comments

  • drei on Simulate a button click via JavaScript
  • Subhee on How to count values with MySQL queries
  • Russell Day on How to hide, show, or toggle your div
  • phi on How to hide, show, or toggle your div
  • bornholy on How to hide, show, or toggle your div

Archives

Categories

  • javascript
  • mysql
  • php

Tag Cloud

add addition and subtraction calculator checkboxes checkEmail content demo demo content div id document getelementbyid dynamic Dynamically dynamic content emailRegEx find form getElementById html javascript input buttons input object input text javascript javascript code javascript demo javascript email javascript function javascript functions loop through menu multiplication mysql mysql query onClick onclick event query regex remove removeChild removeElement replace simulate styling valid email address verification verifyEmail


©2010 Random Snippets