![]() |
Random function limited to the first 10 ID's of db, must take 10 random from entireDB
Hello, Coding Forums, i have problem with option in site.
User goes to the "10 Random Jokes" in the site. In the db there may be tens of thousands of Joke ID's, the user is seeing only the first 10 joke ID's cuz of the desc function of the script and they are mixed, but only the first ten. And if the user refreshes the page, he will see the first 10 jokes from DB again, only by different order again. What needs to happen is when the user goes to the "10 random jokes" he must see 10 random jokes from those tens of thousands Joke ID's and when refreshing the page again 10 random jokes from thousands, not the first 10 jokes only mixed differently, i beleave the function and the module is all here, but can anyone do this ? Code:
<?Code:
/************************************************************** |
Ummm...well yeah, that's what your query asked for.
Code:
ORDER BY emailed_value desc, rating_value DESC limit 0, $display_nr";So just change it to Code:
ORDER BY RAND() LIMIT 10generate_random_array( ) function. The records *WILL* be in random order, already. |
By the by, you could write the condition stuff much simpler:
Code:
$condition = " WHERE validate = 1 AND slng = " $slng ; // assuming slng is a number |
Well no, see there are many options in the site and all working as far as i know and maybe some using the same function, but the "10 random jokes" option is not working. Here are all options:
- Top emaild jokes - the joke that has been email to friend the most - Top jokes by vote - when the people vote for the joke, takes the rating and displays the highest rated joke at the top - 10 random jokes - if the db has 5 000 jokes, the option must take 10 random jokes from those 5 000 jokes everytime, problem is that it's not taking 10 out of 5000 it's taking 10 from the first 10 out of 5000 .. so if the db has 5 000 jokes 4 990 jokes can never be showed, because it's taking random 10 jokes from the first 10 |
Ummm...NEITHER is your "Top jokes by vote" working, if the code you are showing there is all you have.
Your SQL query *ALWAYS* does Code:
ORDER BY emailed_value desc, rating_value DESCI think you will have to show your HTML page where the user requests one of those 3 selections. You are clearly not interacting between the PHP code and the HTML request from the user. If you can show a live URL, that woudl be easiest. |
PLEASE don't tell me that you have SEPARATE PHP pages for those 3 categories!
Why would you do that instead of using one page and conditional SQL? |
Well, here is the link to the site, it's not english, but i have changed the menu to english so that you can know what you are seeing.
=== Link Hiden === |
Well, I can *almost* read the site (I read Russian, so it's familiar looking).
Okay, so the "trick" to the site is your jtype=xxx query string. As in: Code:
http://www.djinchebg.eu/top_emailed_jokes.php?jtype=emailedCode:
$joketype = $_GET["jtype"];You get the *SAME RESULTS* for Code:
http://www.djinchebg.eu/top_ten_jokes.php?cat_id=8&jtype=tenBack in a while with all new code. |
Okay...I do *NOT* code in PHP. So don't be surprised if I make some PHP typos in this.
But here's roughly how I would do it: Code:
<? |
Well, as far as you can, thank you for the time spend
|
| All times are GMT +1. The time now is 10:02 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.