Jump to content

Random Content Displayed on website


couttsey

Recommended Posts

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.