couttsey Posted December 19, 2011 Share Posted December 19, 2011 Hi to everyone , I have used PHP for some basic things in my previous website design but am now venturing into another website for which I have a more complex use for PHP. I plan on making business directory for my local area. People will click on the area of their choice followed by the business type that they require. Then on the results page, they will have a list of all the business types in that particular area. What I would like to be able to do is rather than have the results displayed on the page like this : A Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx Best Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx Top Plumber xxxxx xxxxxx Tel: xxxxx xxxxxx Web: xxxxx xxxxxx E-Mail: xxxxx xxxxxx I would like it so that the same businesses are displayed on the page but either: 1) In a random order each time someone loads the page or 2) In a random order changed every hour The aim is so the businesses all have a shot at appearing nearer the top and aren't penalised for the 1st letter of their company name. Any help on this would be much appreciated, Thank You Quote Link to comment https://forums.phpfreaks.com/topic/253502-random-content-displayed-on-website/ Share on other sites More sharing options...
scootstah Posted December 19, 2011 Share Posted December 19, 2011 array_rand() is your friend here. Quote Link to comment https://forums.phpfreaks.com/topic/253502-random-content-displayed-on-website/#findComment-1299478 Share on other sites More sharing options...
kicken Posted December 19, 2011 Share Posted December 19, 2011 If your using mysql, when your doing your query for the business data you can use the clause: ORDER BY RAND() to get the results in a random order. Not sure if other db's have a similar method. Otherwise in PHP, read the results into an array, then use shuffle() to randomize it before outputting it. Quote Link to comment https://forums.phpfreaks.com/topic/253502-random-content-displayed-on-website/#findComment-1299480 Share on other sites More sharing options...
couttsey Posted December 19, 2011 Author Share Posted December 19, 2011 I forgot to mention. I have heard that it can be done using a .txt file which contains the actual business data. Is this true? If anyone can help with some basic examples that would be a big help. Thank you scootstah and Kicken Quote Link to comment https://forums.phpfreaks.com/topic/253502-random-content-displayed-on-website/#findComment-1299484 Share on other sites More sharing options...
ManiacDan Posted December 19, 2011 Share Posted December 19, 2011 Don't use a text file, use a database. ORDER BY RAND(), once your data is in a database, will order this by rand. Local business directories almost always fail. There is no reason to use your product over Google Maps as you've currently described it. Plus, how would you get the information to display? You already said you know how to make a website that looks like your example. If you're using it from a database (which you absolutely should be), then adding ORDER BY RAN() to the end of your query will change your existing in-order website to a random-order website. Quote Link to comment https://forums.phpfreaks.com/topic/253502-random-content-displayed-on-website/#findComment-1299528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.