Re: Holes in mysql primary key and other db issues...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please include the list in all replies.

Mike Shanley wrote:
Stut wrote:
There is no "simple" way. But this question comes up fairly often, and the usual answer is that there's no need to fill the holes. Why do you think you need to fill the holes? If there is no good reason to do it, why are you bothering?
>
I have a sidebar on my site that gets a few random articles from that table, prints the titles, small blurbs, and a link. The link goes to the main article. I get the random IDs outside of mysql because I've made it more likely for newer articles to be chosen than older ones... This, accomplished via ID, because it's much easier to SELECT count(*) and slant my randomization to the last 25% of ID numbers than any other way I can think of...

Of course, this means that having holes results in empty sidebar boxes... And that's not too good lookin...

How are you selecting random entries? A common way to do this is to use the MySQL rand() function, but that is exceedingly slow.

I would suggest that you get a list of (or a subset of) the IDs in the table, use PHP to randomly select however many you need and then get the full data for those. You can't rely on the IDs, and the work involved in resetting all the IDs such that they're sequential without gaps is not worth it.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux