/ Published in: PHP
                    
                                        
Another version for my old Order by Rand function now it includes some PHP
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
//This is pseudo code for fetching 1 random row. I will update to add a new solution to fetch more random rows.
function randomRow(table, Idcolumn) {
maxRow = query("SELECT MAX(Idcolumn) AS maxID FROM table");
if (maxRow.recordCount > 0) {
do {
randomID = randRange(1, maxRow.maxID);
randomRow = query("SELECT * FROM table WHERE column = randomID");
} while (randomRow.recordCount == 0);
return randomRow;
} else {
return false;
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                