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.

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.