Jump to content

Get random text from database table, how to?


mladja04

Recommended Posts

Hello,

 

Can anyone to help me in this, to tell me which command I to use for this… here is problem (I am new in php):

 

I have database with name BASE1 and it have table which have columns ID, NAME and TEXT. In this table I add some name and some text and on that way many times and in table I have many rows.

I now want to in my php page when user enter some text (or when I define some text) that as result be random 2-3 rows from table text which have NAME as terms.

 

Which command in PHP is for random take from table if entered term is finded in database?

 

EXAMPLE:

- I as admin add several texts in database and 5-6 in NAME have word football.

- User in page1.php enter term: FOOTBALL

- In next page2.php or in same page1.php user will get 2-3 random TEXT from database which have word FOOTBALL from NAME column.

 

(I hope that you understand me)

 

Thank you very much.

 

Link to comment
Share on other sites

Psuedo...

 

put the search word in a variable

query the db using LIKE on the name column (presumes 'word' may be part of name)

put id's of results in an array

shuffle the array

reindex the array using arrary_value

take the first element of the array (it is an id value) , query the db for that record

display the result

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.