mladja04 Posted February 17, 2011 Share Posted February 17, 2011 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. Quote Link to comment Share on other sites More sharing options...
petroz Posted February 17, 2011 Share Posted February 17, 2011 Try something like this SELECT `name`, `text` FROM `table` WHERE `name` = 'peter' ORDER BY RAND() LIMIT 2; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted February 17, 2011 Share Posted February 17, 2011 Google 'mysql why order by rand() is bad' Quote Link to comment Share on other sites More sharing options...
petroz Posted February 17, 2011 Share Posted February 17, 2011 holy schmoley! Thank you for your insight! Quote Link to comment Share on other sites More sharing options...
litebearer Posted February 17, 2011 Share Posted February 17, 2011 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 Quote Link to comment 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.