Page 1 of 1

(O/T) Some funky php coding I just did...

Posted: Tue 11 May 2010 1:12 am
by No457_Squog
Hi guys,

This is completely off-topic, but I thought you might perhaps appreciate/belittle a tiny bit of coding that I did for the No457 website:

Code: Select all

	foreach(array ("access" => null,"actions" => null,"badges" => null,"ranks" => null) as $key => $table) {
		$query = mysql_query ( "SELECT * FROM `". $key ."`" );
		while($results = mysql_fetch_assoc ( $query )) {
			$static[$key][] = $results;
		}
	}
	unset($table);
And the usage:

Code: Select all

echo $static['badges'][4]['long'];
Basically - it a whole heap of 'static' tables in MySQL pumped into one big multidimensional array. I've got to make a few different tweaks to it to get it 100% right, but the basics work just fine :)

What do you guys think?

Posted: Wed 12 May 2010 3:31 am
by IV/JG7_4Shades
Looks like it works. In the olden days, the big problem was to take the PHP data and insert that into Javascript to build dynamic web pages. The easiest way of doing this was to use string transfers. So for the MP I serialized all the SQL recordsets into delimited strings and passed them direct to the Javascript for deserialization (using split). Dumb and clunky, but works well.

But then Ajax came along ....