Friday, October 31, 2008

SQL Random Rows

Select a random row with MySQL:

SELECT column FROM table ORDER BY RAND() LIMIT 1

Select a random row with PostgreSQL:

SELECT column FROM table ORDER BY RANDOM() LIMIT 1

Select a random row with Microsoft SQL Server:

SELECT TOP 1 column FROM table ORDER BY NEWID()

Thanks to: http://www.petefreitag.com/item/466.cfm

Monday, October 27, 2008

MySQL DATETIME and PHP

If you ever had trouble with the date conversions between MySQL's DATETIME field and PHP's date function, here is a way to deal with them.

If you want to take the date from MySQL and display it a certain way with the DATE function in PHP you first need to convert it.  Use the following code:

date(formatstring, strtotime($rowentry));

formatstring is your format string for your date (see date reference)
strtotime is a function in PHP that takes a string
$rowentry is the DATETIME data from your MySQL database

Monday, October 13, 2008

SEO: mod_rewrite and dynamic pages

Search engines don't really like urls that look like http://mysite.com/page.php?id=1&type=23.  Parameters in the URL throw off some search engines and others refuse to index such pages.  To get around this, and still keep your dynamic information, you can do with the mod_rewrite approach with Apache.

This solution is only for the Apache web server.  If you're using another server, such as Windows, you'll need to figure something else out.

The following link details how to use mod_rewrite to have urls that look like http://mysite.com/pages/mypage/mysubpage function like the url at the top.  http://www.workingwith.me.uk/articles/scripting/mod_rewrite

Thursday, October 9, 2008

SQL JOIN References

I had a previous post about LEFT JOINS but I believe w3schools does a better job at explaining them.

Wednesday, October 8, 2008

Background:none doesn't work (in IE)

Something as simple as "background: none;" when placing a "like" item within another doesn't work in IE7 OR IE6.

<ul id="mainNav" style="">

<li style="" class="group1"><a href="#" onmousedown="showhide('mainSubGroup1')">Energy &amp; Resource Management</a>

<ul id="mainSubGroup1">

<li id="s-t01"><a href="#" style="">Environmental Stewardship</a></li>

<li id="s-t02"><a href="/energy/index.php" style="">Climate Savers Computing Initiative</a></li>

<li id="s-t03"><a href="#" style="">Parking and Transportation Services</a></li>

<li id="s-t04"><a href="#" style="">Utilities and Plant Engineering</a></li>



</ul>

</li>



IF there is a background of some sort on the first <li> item, the items in the next level will use them as well. Adding "background:none;" does not work. Must replace with something.

Tuesday, October 7, 2008

Default Firefox Style Sheet

I was trying to find the default CSS used in Firefox and finally found out how to do it.

Simply paste the following into your browser window: file:///C:/Program%20Files/Mozilla%20Firefox/res/html.css