| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Jul 2005 Location: lebanon
Posts: 2,458
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | MYSQL question showing random row from database MYSQL question showing random row from database i am trying to mess around with tags on my site i would like to show random row content from the available rows in my mysql table i want to run something like the cloud of tags how can i do this ? Regards
__________________ Download free MP3 _____________ Get unique visitors 4 NPs (over 800 satisfied) << Check the Holidays offer _____ Email me for fast response ryan [at] ryansdistrict.com ________ My 9000NPs R 4 SALE cheap- Contact me! |
| |
| | #2 (permalink) |
| Danltn.com Join Date: May 2007 Location: Danltn.com / Nottingham, UK
Posts: 1,201
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Either ORDER BY RAND() (Slightly slower) Or use SELECT COUNT(*) to get the number of rows then use rand($start, $count); to get a random row number, then use select to grab that row or rows.
__________________ |
| |
| | THREAD STARTER #3 (permalink) |
| Senior Member Join Date: Jul 2005 Location: lebanon
Posts: 2,458
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | thx the count(*) was what am searching for anyway is it a good idea to place like 30 random links to 30 different topic at the bottom of each page ?
__________________ Download free MP3 _____________ Get unique visitors 4 NPs (over 800 satisfied) << Check the Holidays offer _____ Email me for fast response ryan [at] ryansdistrict.com ________ My 9000NPs R 4 SALE cheap- Contact me! |
| |
| | #4 (permalink) | ||||
| NamePros Regular Join Date: Jul 2005 Location: Tucson, AZ
Posts: 689
![]() |
| ||||
| |
| | THREAD STARTER #5 (permalink) |
| Senior Member Join Date: Jul 2005 Location: lebanon
Posts: 2,458
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | i want it for 2 perposes 1) in a directory i want to give the chance for all pages in directory to get index faster ( because files not getting indexed 2) add random topic in my site how can i make the related thing is it by % like% ?
__________________ Download free MP3 _____________ Get unique visitors 4 NPs (over 800 satisfied) << Check the Holidays offer _____ Email me for fast response ryan [at] ryansdistrict.com ________ My 9000NPs R 4 SALE cheap- Contact me! |
| |
| | #6 (permalink) | ||||
| NamePros Regular Join Date: Jul 2005 Location: Tucson, AZ
Posts: 689
![]() |
I would do it like this... * A table containing keywords (A) * A table containing a list of pages (B) * A table relating (A,B) with unique constraint (A,B) and frequency of occurrence. To load the "related" links, do a keyword inventory on the page and take as many keywords as you need to fill 30 spots, and match up highest occurrence in page with occurrence in the relation table above. Sorry if all that sounded vague, I'm kinda creating the idea in my head as I type, LOL. | ||||
| |
| | THREAD STARTER #7 (permalink) |
| Senior Member Join Date: Jul 2005 Location: lebanon
Posts: 2,458
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | thanks better than nothing ![]() please guys more details if possible
__________________ Download free MP3 _____________ Get unique visitors 4 NPs (over 800 satisfied) << Check the Holidays offer _____ Email me for fast response ryan [at] ryansdistrict.com ________ My 9000NPs R 4 SALE cheap- Contact me! |
| |
| | #8 (permalink) |
| i love automation Join Date: Nov 2007 Location: xrvel.com
Posts: 1,620
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Hi, Ryan. Usually, i push available row IDs to an array. And choose random IDs from the array (which means 30 IDs in your example). Next, i take the data. Here's the code PHP Code: Kurniawan.
__________________
Last edited by xrvel; 03-04-2008 at 02:48 AM.
|
| |