Go Back   Cloud Computing > Support > PHP Forum
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 12-18-11, 06:18
BOD Member
 
Join Date: Nov 2011
Posts: 6
Unhappy random function sql statement

I am trying to figure out how to modify this section of code to make the featured listings random. I tried a couple of variations but I keep getting errors



// Add ORDER BY and LIMIT functions into the SQL
$sql2 = $sql;

// Make all featured listings come first
$sql2.= ' ORDER BY ';

if (!isset($search['seed']))
$search['seed'] = 0;

if (isset($search['order_by']) && $search['order_by'] != 'ANY' &&
($search['order_by'] == 'price' ||
$search['order_by'] == 'date_added' || $search['order_by'] == 'bedrooms' ||
$search['order_by'] == 'bathrooms'))
$sql2.= ' ' . $search['order_by'] . ' ';
else
$sql2.= ' featured, RAND(' . $search['seed'] . ') ';

if (isset($search['order_by']) && $search['order_by'] != 'ANY'
&& isset($search['order_by_type']) && $search['order_by_type'] != 'ANY' &&
($search['order_by_type'] == 'DESC' || $search['order_by_type'] == 'ASC' ))
$sql2.= $search['order_by_type'];

$sql2.= ' LIMIT ' . $results_page . ', ' . $conf['search_results'];
Reply With Quote
  #2 (permalink)  
Old 12-28-11, 03:00
BOD Member
 
Join Date: Jun 2011
Posts: 96
Default

For a list of random results use following query:
Quote:
select * from my_table order by rand( ) limit 10
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


All times are GMT -6. The time now is 01:23.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 1999-2012, BODHost Ltd. All rights reserved.