SQL: SELECT random number of rows
Here’s a quick way of requesting a random number of rows from a MySQL database:
SELECT * FROM <tablename> order by rand() limit <n>;
tablename: is the name of the table you wish to access
n: is thenumber of rows you wish to return
Be careful though, don’t use this logic on a database with a large record, the performance will be unpleasant.
Cyrilic integration of Flex and PHP
A recent project involved integration between a PHP content management tool like Joomla and Adobe Flex 2. I wrote a PHP script that parsed a MySQL database creating an XML structure that was then picked up by a HTTPService in a Flex application.
The information in the database was stored in Cyrillic format, hence when ever I was loading the data in to the SWF compiled file the end result was a collection of garbage data. Setting the actuall HTML to Windows-1251 encoding did not help the situation.
My following approach was to locate a native functionality within the Flex architecture to mediate the situation. Unforchunately I wasn’t successful in aquiring sattisfying examples to solve the problem. For that matter it became sadly obvious that I haven’t seen any flash pages using non/english alphabet [either I haven't been checking international sites that much or Adobe Flex isn't widely used overseas] .
My third approach was to look at the actual php code that was generating the XML structure. I’ve discovered a useful function mb_convert_encoding that eventually solved my problems. Using a simple snippet of code:
mb_convert_encoding($string_to_convert,'UTF-8','Windows-1251');
I was able to convert the data from UTF-8 in to Windows-1251 which allowed me to display the desired Cyrillic characters.