Jump to content
php.lv forumi

No datubāzes izvilkt


Mighty

Recommended Posts

Sveiki.

Man ir datubāze ar dziesmu sarakstu (tur ir tikai 2 rows - id un links).

Kā lai es piespiežu manu web-playeri atskaņot vienu dziesmu randomā no tām, kuras man ir datubāzē?

 

Pagaidām man ir kkas šāds, bet nekas nesanāk - manipulējot ar kodu, vienīgais ko es varu izdarīt, ir panākt ka pleijerī (kurā vajag tikai padot adresi ar tiešo url, lai atskaņotu dziesmu) vainu skan dziesma, kurai ID = 1, vai arī neskan nekas.

 

mysql_query("Select links from muzika ORDER BY RAND() LIMIT 1");

 

 

 

Būšu priecīgs par padomu.

Link to comment
Share on other sites

ORDER BY RAND() LIMIT 1 === source of evil

 

labak izmanto

 

visu skaitu randoma ierkastu.

SELECT FLOOR(RAND() * COUNT(*)) AS rand_row FROM `myTable` WHERE 1;
SELECT `id` FROM `myTable` WHERE 1 LIMIT ".$r['rand_row'].", 1;

Link to comment
Share on other sites

phpmyadmina rakstiju, tur tas where pec noklusejama stav, pec butibas var nerakstit, bet ja sql'a where nosacijums bus vajaddzigs, tad bus jau uzrakstits

kam tur WHERE 1 vajadzīgs?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...