Re: [PHP] Random
On 5/24/2013 3:04 AM, Last Hacker Always onpoint wrote: I needed something like this echo(rand(1,30)) On 5/24/13, Last Hacker Always onpoint wrote: okay thanks tamouse and others you think am not on point hmmm? I'll show you i am. On 5/24/13, tamouse mailing lists wrote: On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint wrote: Hey I need code for random number 1-30 for my site. function rand_from_1_to_30() { return 4; } Apparently, your laziness was overcome by all the abuse you took here. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
Lola On Friday, May 24, 2013, Ashley Sheridan wrote: > > > Last Hacker Always onpoint > wrote: > > >I needed something like this echo(rand(1,30)) > > > >On 5/24/13, Last Hacker Always onpoint > > wrote: > >> okay thanks tamouse and others you think am not on point hmmm? I'll > >> show you i am. > >> > >> On 5/24/13, tamouse mailing lists > > wrote: > >>> On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint > >>> > wrote: > Hey I need code for random number 1-30 for my site. > >>> > >>> function rand_from_1_to_30() { > >>> return 4; > >>> } > >>> > >> > > Did you actually try that? > > Thanks, > Ash > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- - Nick
Re: [PHP] Random
Last Hacker Always onpoint wrote: >I needed something like this echo(rand(1,30)) > >On 5/24/13, Last Hacker Always onpoint wrote: >> okay thanks tamouse and others you think am not on point hmmm? I'll >> show you i am. >> >> On 5/24/13, tamouse mailing lists wrote: >>> On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint >>> wrote: Hey I need code for random number 1-30 for my site. >>> >>> function rand_from_1_to_30() { >>> return 4; >>> } >>> >> Did you actually try that? Thanks, Ash -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
I needed something like this echo(rand(1,30)) On 5/24/13, Last Hacker Always onpoint wrote: > okay thanks tamouse and others you think am not on point hmmm? I'll > show you i am. > > On 5/24/13, tamouse mailing lists wrote: >> On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint >> wrote: >>> Hey I need code for random number 1-30 for my site. >> >> function rand_from_1_to_30() { >> return 4; >> } >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
okay thanks tamouse and others you think am not on point hmmm? I'll show you i am. On 5/24/13, tamouse mailing lists wrote: > On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint > wrote: >> Hey I need code for random number 1-30 for my site. > > function rand_from_1_to_30() { > return 4; > } > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
On Thu, May 23, 2013 at 3:51 PM, Last Hacker Always onpoint wrote: > Hey I need code for random number 1-30 for my site. function rand_from_1_to_30() { return 4; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
His gmail name should be "Last last last last Hacker hacker acker not-cker Never On-point" :) On Thu, May 23, 2013 at 4:51 PM, Last Hacker Always onpoint < lasthack...@gmail.com> wrote: > Hey I need code for random number 1-30 for my site. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Random
On 13-05-23 04:51 PM, Last Hacker Always onpoint wrote: Hey I need code for random number 1-30 for my site. http://php.net/manual/en/function.rand.php -- Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
On May 23, 2013, at 4:54 PM, Daniel Brown wrote: > On Thu, May 23, 2013 at 4:51 PM, Last Hacker Always onpoint > wrote: >> Hey I need code for random number 1-30 for my site. > >You need to know that you've been removed from the list (but you'd > still have to be subscribed to be able to read this). :-) _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
On Thu, May 23, 2013 at 4:51 PM, Last Hacker Always onpoint wrote: > Hey I need code for random number 1-30 for my site. You need to know that you've been removed from the list (but you'd still have to be subscribed to be able to read this). -- Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random
On 23 May 2013, at 21:51, Last Hacker Always onpoint wrote: > Hey I need code for random number 1-30 for my site. Seriously? Did you try to find out how to do this yourself before asking here? http://php.net/rand And, more generally: http://php.net/docs -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random 404 screens
Im pretty sure its not a script error cause it always works a second later jg On Feb 10, 2013, at 2:48 PM, Matijn Woudt wrote: > > > > On Sun, Feb 10, 2013 at 6:53 PM, Jim Giner > wrote: > On 2/10/2013 12:45 PM, Andy McKenzie wrote: > On Sat, Feb 9, 2013 at 11:51 AM, Geoff Shang wrote: > On Sat, 9 Feb 2013, Jim Giner wrote: > > Lately, my web pages are giving me some problems. Once a day or so one or > more of my pages/scripts will give me a 404 error page saying my web page > has timed out. Problem is that the page was just displayed. I click on a > link, the page shows up, I click on a button on it to trigger some activity > and voila! An error. I hit refresh and my page is back and things work ok. > > > Since someone mentioned network issues, I will ask this question. > > Is it actually a "404" page? That is to say, does the string "404" actually > appear in the error document? > > If it does, then this would rule out your home network, as 404 is a response > code returned by the webserver. > > Geoff. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > This is a good point, and one I hadn't thought of. I saw "Network > time out" and thought network problems, but Geoff is right. If it's > actually a 404, it's not a network problem between you and the server. > > -Andy > > The page has a "404" code in it. Next time I see one (been good today so > far) I'll c/p it in here. > > > There are btw much web servers that provide an error, and then give an 404 > error because they can't find an error page for that error code. > > - Matijn
Re: [PHP] Random 404 screens
On Sun, Feb 10, 2013 at 6:53 PM, Jim Giner wrote: > On 2/10/2013 12:45 PM, Andy McKenzie wrote: > >> On Sat, Feb 9, 2013 at 11:51 AM, Geoff Shang >> wrote: >> >>> On Sat, 9 Feb 2013, Jim Giner wrote: >>> >>> Lately, my web pages are giving me some problems. Once a day or so one or more of my pages/scripts will give me a 404 error page saying my web page has timed out. Problem is that the page was just displayed. I click on a link, the page shows up, I click on a button on it to trigger some activity and voila! An error. I hit refresh and my page is back and things work ok. >>> >>> >>> Since someone mentioned network issues, I will ask this question. >>> >>> Is it actually a "404" page? That is to say, does the string "404" >>> actually >>> appear in the error document? >>> >>> If it does, then this would rule out your home network, as 404 is a >>> response >>> code returned by the webserver. >>> >>> Geoff. >>> >>> >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >> This is a good point, and one I hadn't thought of. I saw "Network >> time out" and thought network problems, but Geoff is right. If it's >> actually a 404, it's not a network problem between you and the server. >> >> -Andy >> >> The page has a "404" code in it. Next time I see one (been good today > so far) I'll c/p it in here. > > There are btw much web servers that provide an error, and then give an 404 error because they can't find an error page for that error code. - Matijn
Re: [PHP] Random 404 screens
On 2/10/2013 12:45 PM, Andy McKenzie wrote: On Sat, Feb 9, 2013 at 11:51 AM, Geoff Shang wrote: On Sat, 9 Feb 2013, Jim Giner wrote: Lately, my web pages are giving me some problems. Once a day or so one or more of my pages/scripts will give me a 404 error page saying my web page has timed out. Problem is that the page was just displayed. I click on a link, the page shows up, I click on a button on it to trigger some activity and voila! An error. I hit refresh and my page is back and things work ok. Since someone mentioned network issues, I will ask this question. Is it actually a "404" page? That is to say, does the string "404" actually appear in the error document? If it does, then this would rule out your home network, as 404 is a response code returned by the webserver. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php This is a good point, and one I hadn't thought of. I saw "Network time out" and thought network problems, but Geoff is right. If it's actually a 404, it's not a network problem between you and the server. -Andy The page has a "404" code in it. Next time I see one (been good today so far) I'll c/p it in here. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random 404 screens
On Sat, Feb 9, 2013 at 11:51 AM, Geoff Shang wrote: > On Sat, 9 Feb 2013, Jim Giner wrote: > >> Lately, my web pages are giving me some problems. Once a day or so one or >> more of my pages/scripts will give me a 404 error page saying my web page >> has timed out. Problem is that the page was just displayed. I click on a >> link, the page shows up, I click on a button on it to trigger some activity >> and voila! An error. I hit refresh and my page is back and things work ok. > > > Since someone mentioned network issues, I will ask this question. > > Is it actually a "404" page? That is to say, does the string "404" actually > appear in the error document? > > If it does, then this would rule out your home network, as 404 is a response > code returned by the webserver. > > Geoff. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > This is a good point, and one I hadn't thought of. I saw "Network time out" and thought network problems, but Geoff is right. If it's actually a 404, it's not a network problem between you and the server. -Andy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random 404 screens
On 2/9/2013 11:58 AM, Mike Mackintosh wrote: On Saturday, February 9, 2013 at 11:51 AM, Geoff Shang wrote: On Sat, 9 Feb 2013, Jim Giner wrote: Lately, my web pages are giving me some problems. Once a day or so one or more of my pages/scripts will give me a 404 error page saying my web page has timed out. Problem is that the page was just displayed. I click on a link, the page shows up, I click on a button on it to trigger some activity and voila! An error. I hit refresh and my page is back and things work ok. Since someone mentioned network issues, I will ask this question. Is it actually a "404" page? That is to say, does the string "404" actually appear in the error document? If it does, then this would rule out your home network, as 404 is a response code returned by the webserver. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What about your HTTP server (Apache, nginx, lighttpd)? Is is overloaded or all child-threads/workers busy? I have no idea about how the host server is performing - but this has not happened before now. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random 404 screens
On Saturday, February 9, 2013 at 11:51 AM, Geoff Shang wrote: > On Sat, 9 Feb 2013, Jim Giner wrote: > > > Lately, my web pages are giving me some problems. Once a day or so one or > > more of my pages/scripts will give me a 404 error page saying my web page > > has > > timed out. Problem is that the page was just displayed. I click on a link, > > the page shows up, I click on a button on it to trigger some activity and > > voila! An error. I hit refresh and my page is back and things work ok. > > > > > Since someone mentioned network issues, I will ask this question. > > Is it actually a "404" page? That is to say, does the string "404" > actually appear in the error document? > > If it does, then this would rule out your home network, as 404 is a > response code returned by the webserver. > > Geoff. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > What about your HTTP server (Apache, nginx, lighttpd)? Is is overloaded or all child-threads/workers busy?
Re: [PHP] Random 404 screens
On Sat, 9 Feb 2013, Jim Giner wrote: Lately, my web pages are giving me some problems. Once a day or so one or more of my pages/scripts will give me a 404 error page saying my web page has timed out. Problem is that the page was just displayed. I click on a link, the page shows up, I click on a button on it to trigger some activity and voila! An error. I hit refresh and my page is back and things work ok. Since someone mentioned network issues, I will ask this question. Is it actually a "404" page? That is to say, does the string "404" actually appear in the error document? If it does, then this would rule out your home network, as 404 is a response code returned by the webserver. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random 404 screens
On 2/9/2013 11:21 AM, Andy McKenzie wrote: Smart money is that it's nothing to do with you; in my experience, that's usually a network problem. It could be on your end (I'm seeing that a lot more often now that I've moved to a new house, or it could be a problem with the server's connection. I just loaded your page half a dozen times in short succession, and it was fine, so that makes me think it's likely to be at your end... or somewhere between you and the server, you never know. Well I feel better about my work - but now I guess I have to investigate if my home network is having a problem. Thanks for taking the time. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random 404 screens
On Sat, Feb 9, 2013 at 10:41 AM, Jim Giner wrote: > This is a tough one. > > Lately, my web pages are giving me some problems. Once a day or so one or > more of my pages/scripts will give me a 404 error page saying my web page > has timed out. Problem is that the page was just displayed. I click on a > link, the page shows up, I click on a button on it to trigger some activity > and voila! An error. I hit refresh and my page is back and things work ok. > > Some background. My pages/appls/development does not do much of anything > other than record/display stuff from my dbs and show off some pics. Nothing > fancy other than some js to enhance the viewing of these pages. No playing > with anything time-related and very few cookies. So I don't have a clue as > to what constitues a "web page timeout". > > Can anyone enlighten me as to what I should be looking for here? Or even if > it is something I'm the cause of? > > For those who wish to experiment my site is jimginer dot net. Can't > guarantee you'll get the error, but you might. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Smart money is that it's nothing to do with you; in my experience, that's usually a network problem. It could be on your end (I'm seeing that a lot more often now that I've moved to a new house, or it could be a problem with the server's connection. I just loaded your page half a dozen times in short succession, and it was fine, so that makes me think it's likely to be at your end... or somewhere between you and the server, you never know. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Flash Movies
On Sun, Sep 20, 2009 at 11:33 AM, Ashley Sheridan wrote: > On Sun, 2009-09-20 at 11:30 -0400, Gary wrote: > >> A question was posted on another board that the poster wanted random flash >> movies to display as the page is reloaded. I posted the script below and >> said I thought it could be adapted but that the echo would probably need to >> change. Can someone offer some guidance on this? Thanks >> >> Gary >> >> > //Chooses a random number >> $num = Rand (1,6); >> //Based on the random number, gives a quote >> switch ($num) >> { >> case 1: >> echo ""; >> break; >> case 2: >> echo ""; >> break; >> case 3: >> echo ""; >> break; >> case 4: >> echo ""; >> break; >> case 5: >> echo ""; >> break; >> case 6: >> echo ""; >> } >> ?> >> >> >> >> __ Information from ESET Smart Security, version of virus signature >> database 4441 (20090919) __ >> >> The message was checked by ESET Smart Security. >> >> http://www.eset.com >> >> >> >> >> > > Call the movies 1.swf, 2.swf it will make it easier. If not, put them in > an associative array. Then, once the random number has been chosen, > output all the code needed for embedding the Flash player, and in-place > of the movie clip name, put your variable. The switch above is > unnecessary, as it will mean a lot of duplication. > > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > What Ash said, something like: $flashVids = array(); $flashVids[] = '/path/to/movie.swf'; $flashVids[] = '/different/path/movie.swf'; //add any amount more $randomMoviePath = $flashVids[array_rand($flashVids)]; echo "Random flash movie: " . $randomMoviePath; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Flash Movies
On Sun, 2009-09-20 at 11:30 -0400, Gary wrote: > A question was posted on another board that the poster wanted random flash > movies to display as the page is reloaded. I posted the script below and > said I thought it could be adapted but that the echo would probably need to > change. Can someone offer some guidance on this? Thanks > > Gary > > //Chooses a random number > $num = Rand (1,6); > //Based on the random number, gives a quote > switch ($num) > { > case 1: > echo ""; > break; > case 2: > echo ""; > break; > case 3: > echo ""; > break; > case 4: > echo ""; > break; > case 5: > echo ""; > break; > case 6: > echo ""; > } > ?> > > > > __ Information from ESET Smart Security, version of virus signature > database 4441 (20090919) __ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > > > Call the movies 1.swf, 2.swf it will make it easier. If not, put them in an associative array. Then, once the random number has been chosen, output all the code needed for embedding the Flash player, and in-place of the movie clip name, put your variable. The switch above is unnecessary, as it will mean a lot of duplication. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Random php
On Sun, Apr 12, 2009 at 1:32 AM, Gary wrote: > I had been on that site before, but seems like it is a breeding ground for > spam and links to "free" commercial sites. Ran into a few bad or broken > links, several listings as different scripts only to take you to the same > "best price hosting" company with no scripts at all. Is this common, is > that site on its way out? > > Would you have another suggestion? > > Well, I also browsed through that site.. yes what you claimed is true. Facility/Opportunity comes with a price. So, you can go through the ads/sponsors but there are working examples/free code snippets as well. Just googling with that "random quote php" could yield you a lots of practical results. Regards Lenin www.twitter.com/nine_L
Re: [PHP] Random php
I had been on that site before, but seems like it is a breeding ground for spam and links to "free" commercial sites. Ran into a few bad or broken links, several listings as different scripts only to take you to the same "best price hosting" company with no scripts at all. Is this common, is that site on its way out? Would you have another suggestion? Thanks for your help. Gary "Phpster" wrote in message news:146a4da4-0114-474c-92f8-b8d3a5ecc...@gmail.com... > > > On Apr 11, 2009, at 10:12, "Gary" wrote: > >> Is there a way to have a php include called ramdomly? For example, I >> have >> an area that I am using to show various quotes and I would like the >> quotes >> to be ramdom. >> >> Thanks for your help >> >> Gary >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Best is to use a storage system ( either file with a quote in each line > or a database ) and then randomly select a record from the database or > an item from the file. If you do a quick search on www.hotscripts.com or > just goodle 'php random quote' you'll see lots of samples or complete > code. > > Bastien -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random php
Thanks much for your quick reply, I'll take a look (and maybe even find one that spell checks my posts first!). Gary "Phpster" wrote in message news:146a4da4-0114-474c-92f8-b8d3a5ecc...@gmail.com... > > > On Apr 11, 2009, at 10:12, "Gary" wrote: > >> Is there a way to have a php include called ramdomly? For example, I >> have >> an area that I am using to show various quotes and I would like the >> quotes >> to be ramdom. >> >> Thanks for your help >> >> Gary >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > Best is to use a storage system ( either file with a quote in each line > or a database ) and then randomly select a record from the database or > an item from the file. If you do a quick search on www.hotscripts.com or > just goodle 'php random quote' you'll see lots of samples or complete > code. > > Bastien -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random php
On Apr 11, 2009, at 10:12, "Gary" wrote: Is there a way to have a php include called ramdomly? For example, I have an area that I am using to show various quotes and I would like the quotes to be ramdom. Thanks for your help Gary -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Best is to use a storage system ( either file with a quote in each line or a database ) and then randomly select a record from the database or an item from the file. If you do a quick search on www.hotscripts.com or just goodle 'php random quote' you'll see lots of samples or complete code. Bastien -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
At 11:35 AM -0600 11/6/08, WEISD wrote: http://www.weisd.com/store2/WINHD-9022.php Not me -- I get a normal distribution. Cheers, tedd Thanks Tedd, That is because it is using time now and not rand... Just as point of notice. When I ask a question and provide a url, I keep the url there "as-is" until the question is answered -- at which time I remove the example. If the url is not there, then people can assume that the problem is solved. This allows people to see the problem and prevents wasting time. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
1. change the number to a string: $t = (string) time(); 2. chop off the last char of the string: $char = substr($t, -1); 3. you're done...: include "footer$char.html"; Time wins certainly produces better results, at least for what I am doing, than rand... Thanks all for your input... Nice NG here -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
Stephen wrote: > On Thu, 11/6/08, WEISD <[EMAIL PROTECTED]> wrote: > > >>> That is strange. I get pretty balanced results on this >>> >> computer. >> >>> >> >>> $histogram = array_fill(1, 10, 0); >>> >>> $iterations = 20; >>> >>> for ($i = 0; $i < $iterations; ++$i) { >>>++$histogram[round(rand(1, 10))]; >>> } >>> >>> print_r($histogram); >>> >>> ?> >>> >>> Andrew >>> >> Simple code, >> >> > $number = rand(1, 10); >> >> include("footer$number.html"); ?> >> >> You can see it in action here at the bottom of the page >> there is a footer. >> Each footer is the same right now except I have numbered >> them for testing. >> >> As I refresh the page, I get footer10 almost always with >> an occasional 2 or >> 4 here and there... >> >> http://www.weisd.com/store2/WINHD-9022.php >> > Computer functions to generate random numbers are not designed to do what > their name suggests. > > Software testing requires repeatability, and this includes random number > generation. > > Without knowing how PHP seeds the generator it is difficult to predict what > it will do. > > I still think taking the last digit of the current time is your best solution. > > Stephen > > The PHP developers understood the random problem and the need for predictability, so they did 2 things. 1. Randomly seed the random number generator every time 2. Allow you to set the seed for predictability http://us.php.net/srand Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
http://www.weisd.com/store2/WINHD-9022.php Not me -- I get a normal distribution. Cheers, tedd Thanks Tedd, That is because it is using time now and not rand... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
At 10:30 AM -0600 11/6/08, WEISD wrote: You can see it in action here at the bottom of the page there is a footer. Each footer is the same right now except I have numbered them for testing. As I refresh the page, I get footer10 almost always with an occasional 2 or 4 here and there... http://www.weisd.com/store2/WINHD-9022.php Not me -- I get a normal distribution. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
WEISD wrote: > >> >> Computer functions to generate random numbers are not designed to do >> what their name suggests. >> >> Software testing requires repeatability, and this includes random >> number generation. >> >> Without knowing how PHP seeds the generator it is difficult to predict >> what it will do. >> >> I still think taking the last digit of the current time is your best >> solution. >> >> Stephen > > I like the idea of using the time but don't like the idea of spending > the rest of the day learning how to parse out the numbers I need from > the time... > Really, you think this step is difficult? Try looking at the page http://php.net/date it will give you all that you need. $second = (int)date('s'); This will give you the current second of the current minute of the current Anyways. Take that and run it through a modulo then add one to keep it within the 1-10. This should do -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
WEISD wrote: Computer functions to generate random numbers are not designed to do what their name suggests. Software testing requires repeatability, and this includes random number generation. Without knowing how PHP seeds the generator it is difficult to predict what it will do. I still think taking the last digit of the current time is your best solution. Stephen I like the idea of using the time but don't like the idea of spending the rest of the day learning how to parse out the numbers I need from the time... 1. change the number to a string: $t = (string) time(); 2. chop off the last char of the string: $char = substr($t, -1); 3. you're done...: include "footer$char.html"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
That is strange. I get pretty balanced results on this computer. Andrew Simple code, You can see it in action here at the bottom of the page there is a footer. Each footer is the same right now except I have numbered them for testing. As I refresh the page, I get footer10 almost always with an occasional 2 or 4 here and there... http://www.weisd.com/store2/WINHD-9022.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
Computer functions to generate random numbers are not designed to do what their name suggests. Software testing requires repeatability, and this includes random number generation. Without knowing how PHP seeds the generator it is difficult to predict what it will do. I still think taking the last digit of the current time is your best solution. Stephen I like the idea of using the time but don't like the idea of spending the rest of the day learning how to parse out the numbers I need from the time... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
WEISD wrote: > >> That is strange. I get pretty balanced results on this computer. >> >> > >> $histogram = array_fill(1, 10, 0); >> >> $iterations = 20; >> >> for ($i = 0; $i < $iterations; ++$i) { >>++$histogram[round(rand(1, 10))]; >> } >> >> print_r($histogram); >> >> ?> >> >> Andrew > > Simple code, > > $number = rand(1, 10); > > include("footer$number.html"); ?> > > You can see it in action here at the bottom of the page there is a > footer. Each footer is the same right now except I have numbered them > for testing. > > As I refresh the page, I get footer10 almost always with an > occasional 2 or 4 here and there... > > http://www.weisd.com/store2/WINHD-9022.php > > > Which PHP version are you running? After 4.2.0, it should be random each call. Otherwise, use srand(); Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
On Thu, 11/6/08, WEISD <[EMAIL PROTECTED]> wrote: > > That is strange. I get pretty balanced results on this > computer. > > > > > > > $histogram = array_fill(1, 10, 0); > > > > $iterations = 20; > > > > for ($i = 0; $i < $iterations; ++$i) { > >++$histogram[round(rand(1, 10))]; > > } > > > > print_r($histogram); > > > > ?> > > > > Andrew > > Simple code, > > $number = rand(1, 10); > > include("footer$number.html"); ?> > > You can see it in action here at the bottom of the page > there is a footer. > Each footer is the same right now except I have numbered > them for testing. > > As I refresh the page, I get footer10 almost always with > an occasional 2 or > 4 here and there... > > http://www.weisd.com/store2/WINHD-9022.php Computer functions to generate random numbers are not designed to do what their name suggests. Software testing requires repeatability, and this includes random number generation. Without knowing how PHP seeds the generator it is difficult to predict what it will do. I still think taking the last digit of the current time is your best solution. Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Random number generator
[snip] You can see it in action here at the bottom of the page there is a footer. Each footer is the same right now except I have numbered them for testing. As I refresh the page, I get footer10 almost always with an occasional 2 or 4 here and there... [/snip] So there fore it is random, or at least as random as it can be. If you want it to be random but not be the same as the last value generated you have to do some more complex programming. But then you have really made things less random. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
""Gary M. Josack"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Stephen wrote: On a php web page I want to generate a random number between say 1 and 10 and then use that number to reference a particular file in an include tag. Is there an easy way to do this? Get the time and use the last digit converting 0 to 10. Stephen rand(1, 10); Thanks for the help!! php's random number generator seems to have favorite numbers. rand(1, 10); produces 10 & 3, 90% of the time -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
On Thu, Nov 6, 2008 at 10:53 AM, WEISD <[EMAIL PROTECTED]> wrote: > > ""Gary M. Josack"" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> >> Stephen wrote: On a php web page I want to generate a random number between say 1 and 10 and then use that number to reference a particular file in an include tag. Is there an easy way to do this? >>> >>> Get the time and use the last digit converting 0 to 10. >>> >>> Stephen >>> >>> >> rand(1, 10); > > Thanks for the help!! > > php's random number generator seems to have favorite numbers. > > rand(1, 10); produces 10 & 3, 90% of the time > That is strange. I get pretty balanced results on this computer. Array ( [1] => 19991 (10.00%) [2] => 19981 (9.99%) [3] => 20011 (10.01%) [4] => 19998 (10.00%) [5] => 20049 (10.02%) [6] => 20008 (10.00%) [7] => 19983 (9.99%) [8] => 19986 (9.99%) [9] => 20007 (10.00%) [10] => 19986 (9.99%) ) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
On Thu, Nov 6, 2008 at 3:52 AM, Amisha_Sharma <[EMAIL PROTECTED]> wrote: > > Hi > > you can use PHP rand() function for selecting a random number between 1 to > 100. Amisha, Welcome to the list, but please don't top post. For a list of all the guidelines for the official PHP lists, including this one, you can check it out here: http://www.php.net/reST/php-src/README.MAILINGLIST_RULES -- http://www.parasane.net/ [EMAIL PROTECTED] || [EMAIL PROTECTED] Ask me about our current hosting/dedicated server deals! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
Hi you can use PHP rand() function for selecting a random number between 1 to 100. http://www.senpai-it.com/dedicated_servers.php Senpai IT Solutions Dedicated Server at low cost WEISD wrote: > > > On a php web page I want to generate a random number between say 1 and 10 > and then use that number to reference a particular file in an include tag. > > > > Is there an easy way to do this? > > Thanks > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- View this message in context: http://www.nabble.com/Random-number-generator-tp20347780p20357212.html Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
On Wed, 2008-11-05 at 12:41 -0600, WEISD wrote: > On a php web page I want to generate a random number between say 1 and 10 > and then use that number to reference a particular file in an include tag. > > > > Is there an easy way to do this? > > Thanks > include "manual.php"; lesson = new manual(); lesson->math->rand->read(); Ash www.ashleysheridan.co.uk
Re: [PHP] Random number generator
Umm I must notify you, just in case you don't know this, that you have to be aware of the fact that the humanity haven't found a way to get a random number (yet. they are working on it while I'm writing this..) (; On Wed, Nov 5, 2008 at 9:43 PM, Gary M. Josack <[EMAIL PROTECTED]> wrote: > WEISD wrote: > >> Just starting out, thanks. >> >> So, >> >> > >> $number = rand(1, 10); >> >> include('$number.html'); ?> >> >> >> I should have prefaced the question with, New to PHP... >> >> >> >> >> >> ""TG"" <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> >>> Here's how you generate a random number: >>> http://us.php.net/manual/en/function.rand.php >>> >>> There are a number of things you can do with that to select a random file >>> and >>> include it. Have an associative array where the random number matches an >>> array key and the value is the filename you want, is one method. >>> >>> Just starting out with PHP or is this a homework assignment? :) >>> >>> -TG >>> >>> - Original Message - >>> From: "WEISD" <[EMAIL PROTECTED]> >>> To: php-general@lists.php.net >>> Date: Wed, 5 Nov 2008 12:41:21 -0600 >>> Subject: [PHP] Random number generator >>> >>> On a php web page I want to generate a random number between say 1 and 10 and then use that number to reference a particular file in an include tag. Is there an easy way to do this? Thanks >>> >>> >> use double quotes instead of single quotes, else you will be trying to > literally include '$number.html' > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Random number generator
WEISD wrote: Just starting out, thanks. So, I should have prefaced the question with, New to PHP... ""TG"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Here's how you generate a random number: http://us.php.net/manual/en/function.rand.php There are a number of things you can do with that to select a random file and include it. Have an associative array where the random number matches an array key and the value is the filename you want, is one method. Just starting out with PHP or is this a homework assignment? :) -TG - Original Message - From: "WEISD" <[EMAIL PROTECTED]> To: php-general@lists.php.net Date: Wed, 5 Nov 2008 12:41:21 -0600 Subject: [PHP] Random number generator On a php web page I want to generate a random number between say 1 and 10 and then use that number to reference a particular file in an include tag. Is there an easy way to do this? Thanks use double quotes instead of single quotes, else you will be trying to literally include '$number.html' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
Stephen wrote: On a php web page I want to generate a random number between say 1 and 10 and then use that number to reference a particular file in an include tag. Is there an easy way to do this? Get the time and use the last digit converting 0 to 10. Stephen rand(1, 10); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
Just starting out, thanks. So, I should have prefaced the question with, New to PHP... ""TG"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Here's how you generate a random number: http://us.php.net/manual/en/function.rand.php There are a number of things you can do with that to select a random file and include it. Have an associative array where the random number matches an array key and the value is the filename you want, is one method. Just starting out with PHP or is this a homework assignment? :) -TG - Original Message - From: "WEISD" <[EMAIL PROTECTED]> To: php-general@lists.php.net Date: Wed, 5 Nov 2008 12:41:21 -0600 Subject: [PHP] Random number generator On a php web page I want to generate a random number between say 1 and 10 and then use that number to reference a particular file in an include tag. Is there an easy way to do this? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
Here's how you generate a random number: http://us.php.net/manual/en/function.rand.php There are a number of things you can do with that to select a random file and include it. Have an associative array where the random number matches an array key and the value is the filename you want, is one method. Just starting out with PHP or is this a homework assignment? :) -TG - Original Message - From: "WEISD" <[EMAIL PROTECTED]> To: php-general@lists.php.net Date: Wed, 5 Nov 2008 12:41:21 -0600 Subject: [PHP] Random number generator > > On a php web page I want to generate a random number between say 1 and 10 > and then use that number to reference a particular file in an include tag. > > > > Is there an easy way to do this? > > Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random number generator
> On a php web page I want to generate a random number > between say 1 and 10 > and then use that number to reference a particular file in > an include tag. > > > > Is there an easy way to do this? Get the time and use the last digit converting 0 to 10. Stephen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random SELECT SQL list
Hi Larry,Paul,Zoltán Thanks for your messages, adding ORDER BY RAND () worked just fine :) Eduardo "Larry Garfield" <[EMAIL PROTECTED]> escribió en el mensaje news:[EMAIL PROTECTED] > On Wednesday 16 May 2007, Eduardo Vizcarra wrote: >> Hi >> >> I would like to know if a SELECT SQL query list of records can be >> unsorted. >> SELECT statement retrieves a list of records from a certain table >> starting >> from record # 1 till record #N and when publishing the records, this is >> how >> it is presented, in a sequential way, is there any way to not present >> them >> in a sequential way ? e.g. if a user accesses a web page then he will see >> record #3 and then #7 and so on, another user accesses the same web page >> and he might see record #8 and then record#2. etc >> >> any experience on how to do this ? > > This is really an SQL question, but it's quite easy. Assuming MySQL: > > $result = mysql_query("SELECT * FROM foo WHERE bar='baz' ORDER BY > RAND()"); > // Do stuff here. > > -- > Larry Garfield AIM: LOLG42 > [EMAIL PROTECTED] ICQ: 6817012 > > "If nature has made any one thing less susceptible than all others of > exclusive property, it is the action of the thinking power called an idea, > which an individual may exclusively possess as long as he keeps it to > himself; but the moment it is divulged, it forces itself into the > possession > of every one, and the receiver cannot dispossess himself of it." -- > Thomas > Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random SELECT SQL list
2007. 05. 17, csütörtök keltezéssel 00.45-kor Larry Garfield ezt írta: > On Wednesday 16 May 2007, Eduardo Vizcarra wrote: > > Hi > > > > I would like to know if a SELECT SQL query list of records can be unsorted. > > SELECT statement retrieves a list of records from a certain table starting > > from record # 1 till record #N and when publishing the records, this is how > > it is presented, in a sequential way, is there any way to not present them > > in a sequential way ? e.g. if a user accesses a web page then he will see > > record #3 and then #7 and so on, another user accesses the same web page > > and he might see record #8 and then record#2. etc > > > > any experience on how to do this ? > > This is really an SQL question, but it's quite easy. Assuming MySQL: > > $result = mysql_query("SELECT * FROM foo WHERE bar='baz' ORDER BY RAND()"); > // Do stuff here. ORDER BY RAND can be very unefficient on large tables. some useful info here: http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/ greets Zoltán Németh > > -- > Larry GarfieldAIM: LOLG42 > [EMAIL PROTECTED] ICQ: 6817012 > > "If nature has made any one thing less susceptible than all others of > exclusive property, it is the action of the thinking power called an idea, > which an individual may exclusively possess as long as he keeps it to > himself; but the moment it is divulged, it forces itself into the possession > of every one, and the receiver cannot dispossess himself of it." -- Thomas > Jefferson > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random SELECT SQL list
On Wednesday 16 May 2007, Eduardo Vizcarra wrote: > Hi > > I would like to know if a SELECT SQL query list of records can be unsorted. > SELECT statement retrieves a list of records from a certain table starting > from record # 1 till record #N and when publishing the records, this is how > it is presented, in a sequential way, is there any way to not present them > in a sequential way ? e.g. if a user accesses a web page then he will see > record #3 and then #7 and so on, another user accesses the same web page > and he might see record #8 and then record#2. etc > > any experience on how to do this ? This is really an SQL question, but it's quite easy. Assuming MySQL: $result = mysql_query("SELECT * FROM foo WHERE bar='baz' ORDER BY RAND()"); // Do stuff here. -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random SELECT SQL list
At 5/16/2007 09:40 PM, Eduardo Vizcarra wrote: I would like to know if a SELECT SQL query list of records can be unsorted. SELECT statement retrieves a list of records from a certain table starting from record # 1 till record #N and when publishing the records, this is how it is presented, in a sequential way, is there any way to not present them in a sequential way ? e.g. if a user accesses a web page then he will see record #3 and then #7 and so on, another user accesses the same web page and he might see record #8 and then record#2. etc Found on this page: http://dev.mysql.com/doc/refman/5.1/en/select.html " Posted by Boris Aranovich on June 9 2004 2:33pm I am using this way to select random row or rows: SELECT * [or any needed fileds], idx*0+RAND() as rnd_id FROM tablename ORDER BY rnd_id LIMIT 1 [or the number of rows] Meanwhile, I didn't stumble in any problems with this usage. I picked this method in some forum, don't remember when, where or by who was it introduced :) " -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
On Sat, 2007-03-24 at 08:24 -0400, Jim McIntyre wrote: > IIRC, the OP wanted to generate a unique key precisely to keep from > revealing the record ID to the end user... what about taking the > auto_increment value (easy to generate, assured to be unique) adding its > MD5 hash to another column in the table, then using that as the > "published" ID? > > The only disadvantage I see is that the MD5 hash isn't very > human-friendly, so using it for an account or member number, or something > like that the user might have to write down or read to a customer service > rep on the phone, might be difficult. It's more likely that he wants the unique ID so that he can serve up a document or image such that other documents or images can't be retrieved just by incrementing the ID in the URL. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
IIRC, the OP wanted to generate a unique key precisely to keep from revealing the record ID to the end user... what about taking the auto_increment value (easy to generate, assured to be unique) adding its MD5 hash to another column in the table, then using that as the "published" ID? The only disadvantage I see is that the MD5 hash isn't very human-friendly, so using it for an account or member number, or something like that the user might have to write down or read to a customer service rep on the phone, might be difficult. -Jim On Fri, March 23, 2007 9:35 pm, Richard Lynch wrote: > Use auto_increment. > > It's not random, but you should never show it to the end user anyway, > so who cares? > > Another option is to use http://php.net/uniqid and you can create a > UNIQUE INDEX on the column and simply check mysql_errno() to see if > it's 1023 (or is it 2023?) when you insert to see if you had a > collision. > > On Wed, March 21, 2007 12:18 pm, [EMAIL PROTECTED] wrote: >> Hello, >> >> I want to add a random unique ID to a Mysql table. Collisions >> are unlikely but possible so to handle those cases I'd like to >> regenerate the random ID until there is no collision and only >> then add my row. Any suggestions for a newbie as to the right >> way to go about doing this? >> >> Best, >> >> Craig >> >> -- >> - Virtual Phonecards - Instant Pin by Email - >> - Large Selection - Great Rates- >> - http://speedypin.com/?aff=743&co_branded=1 - >> -- >> >> >> ** >> ** >> * Craig Spencer * >> * [EMAIL PROTECTED]* >> ** >> ** >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > > > -- > Some people have a "gift" link here. > Know what I want? > I want you to buy a CD from some indie artist. > http://cdbaby.com/browse/from/lynch > Yeah, I get a buck. So? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
Use auto_increment. It's not random, but you should never show it to the end user anyway, so who cares? Another option is to use http://php.net/uniqid and you can create a UNIQUE INDEX on the column and simply check mysql_errno() to see if it's 1023 (or is it 2023?) when you insert to see if you had a collision. On Wed, March 21, 2007 12:18 pm, [EMAIL PROTECTED] wrote: > Hello, > > I want to add a random unique ID to a Mysql table. Collisions > are unlikely but possible so to handle those cases I'd like to > regenerate the random ID until there is no collision and only > then add my row. Any suggestions for a newbie as to the right > way to go about doing this? > > Best, > > Craig > > -- > - Virtual Phonecards - Instant Pin by Email - > - Large Selection - Great Rates- > - http://speedypin.com/?aff=743&co_branded=1 - > -- > > > ** > ** > * Craig Spencer * > * [EMAIL PROTECTED]* > ** > ** > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
2007. 03. 23, péntek keltezéssel 15.13-kor tedd ezt írta: > At 9:15 AM +0100 3/23/07, Németh Zoltán wrote: > >2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: > >> At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: > >> >2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: > >> > > >> > > As for efficiency, that's probably not > >>even worth mentioning in this case. > >> > > >> >why not? you would use 2 sql queries while I would use one most of the > >> >time and 2 in case of already reserved ID - that is almost twice as much > >> >processor time > >> >that may count much if the routine is used frequently > >> > >> Go ahead, try it, and tell me how much time it cost. > >> > >> From experience, there are things one can spend > >> their time optimizing and there are other things > >> that one should be able to see that aren't worth > >> pursing. > >> > >> I've been wrong before, but you're open to > >>prove me wrong again, if you like. > > > >okay, I've got up earlier and made a little benchmark. The result > >suprised me, and proved you right. ;) > > Németh: > > Thanks for trying, but I said what I did because > I knew from experience that these types of > actions are blinding fast and getting faster all > the time. > > I'm not suggesting to dispense with looking for > less operations, but sometimes the effort doesn't > exceed other benefits in readability, easier > logic, simpler code, and time spent developing > code. We have been rather slow to realize changes > the speed and memory of hardware. > > For example, we recently had a discussion on the > difference between using " " a "concern". When in fact, if is of no noticeable > or significant concern at all. It's like > discussing a grain of sand on the beach. > > Not that you did this, but sometimes it's best to > figure out what's important and what's not before > making it an issue. yeah, you're right again :) (however my first name is still Zoltán instead of Németh ;) ) that's what I did now. I figured out it's not important. thanks for inspiring me to do that :) greets Zoltán Németh > > Cheers, > > tedd > > -- > --- > http://sperling.com http://ancientstones.com http://earthstones.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
At 9:15 AM +0100 3/23/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: >2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: > > > As for efficiency, that's probably not even worth mentioning in this case. > >why not? you would use 2 sql queries while I would use one most of the >time and 2 in case of already reserved ID - that is almost twice as much >processor time >that may count much if the routine is used frequently Go ahead, try it, and tell me how much time it cost. From experience, there are things one can spend their time optimizing and there are other things that one should be able to see that aren't worth pursing. I've been wrong before, but you're open to prove me wrong again, if you like. okay, I've got up earlier and made a little benchmark. The result suprised me, and proved you right. ;) Németh: Thanks for trying, but I said what I did because I knew from experience that these types of actions are blinding fast and getting faster all the time. I'm not suggesting to dispense with looking for less operations, but sometimes the effort doesn't exceed other benefits in readability, easier logic, simpler code, and time spent developing code. We have been rather slow to realize changes the speed and memory of hardware. For example, we recently had a discussion on the difference between using ""a "concern". When in fact, if is of no noticeable or significant concern at all. It's like discussing a grain of sand on the beach. Not that you did this, but sometimes it's best to figure out what's important and what's not before making it an issue. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
2007. 03. 23, péntek keltezéssel 08.13-kor Robert Cummings ezt írta: > On Fri, 2007-03-23 at 09:15 +0100, Németh Zoltán wrote: > > > // method 2 > > $time = microtime(TRUE); > > for ($i = 1; $i <= 5000; $i++) { > > $done = FALSE; > > while (!$done) { > > $id = md5((microtime(TRUE) * (rand(1,1000) / 100))); > > $sql = "INSERT INTO idtest (id,cnt) VALUES ('$id', $i)"; > > $result = mysql_query($sql); > > if ($result) { $done = TRUE; } > > } > > } > > $end = microtime(TRUE) - $time; > > echo "method 2 time: " . $end . ""; > > One of the problems with the above style is that if the query fails for > some other reason (typo, no permissions, database temporarily > unavailable, etc) the code will run indefinitely (or until it gets > killed for too much time). That's a very dirty way to manage failed > inserts due to dupes. yes, of course. that's good only for this small test, not for real life use ;) for real use one should check mysql_errno end take action based on that greets Zoltán Németh > > Cheers, > Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
On Fri, 2007-03-23 at 09:15 +0100, Németh Zoltán wrote: > // method 2 > $time = microtime(TRUE); > for ($i = 1; $i <= 5000; $i++) { > $done = FALSE; > while (!$done) { > $id = md5((microtime(TRUE) * (rand(1,1000) / 100))); > $sql = "INSERT INTO idtest (id,cnt) VALUES ('$id', $i)"; > $result = mysql_query($sql); > if ($result) { $done = TRUE; } > } > } > $end = microtime(TRUE) - $time; > echo "method 2 time: " . $end . ""; One of the problems with the above style is that if the query fails for some other reason (typo, no permissions, database temporarily unavailable, etc) the code will run indefinitely (or until it gets killed for too much time). That's a very dirty way to manage failed inserts due to dupes. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: > At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: > >2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: > > > > > As for efficiency, that's probably not even worth mentioning in this > > case. > > > >why not? you would use 2 sql queries while I would use one most of the > >time and 2 in case of already reserved ID - that is almost twice as much > >processor time > >that may count much if the routine is used frequently > > Go ahead, try it, and tell me how much time it cost. > > From experience, there are things one can spend > their time optimizing and there are other things > that one should be able to see that aren't worth > pursing. > > I've been wrong before, but you're open to prove me wrong again, if you like. okay, I've got up earlier and made a little benchmark. The result suprised me, and proved you right. ;) here is the code: "; // clean up table $sql = "DELETE FROM idtest"; mysql_query($sql); // method 2 $time = microtime(TRUE); for ($i = 1; $i <= 5000; $i++) { $done = FALSE; while (!$done) { $id = md5((microtime(TRUE) * (rand(1,1000) / 100))); $sql = "INSERT INTO idtest (id,cnt) VALUES ('$id', $i)"; $result = mysql_query($sql); if ($result) { $done = TRUE; } } } $end = microtime(TRUE) - $time; echo "method 2 time: " . $end . ""; ?> and the output: method 1 time: 97.1539468765 method 2 time: 93.4973130226 this clearly shows that the method I suggested is only slightly faster, so that difference really isn't worth mentioning as you said :) however, the difference may be slightly bigger when using better ID generation functions, mine above is very basic so it might have more repetitions... greets Zoltán Németh > > Cheers, > > tedd > -- > --- > http://sperling.com http://ancientstones.com http://earthstones.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: > At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: > >2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: > > > > > As for efficiency, that's probably not even worth mentioning in this > > case. > > > >why not? you would use 2 sql queries while I would use one most of the > >time and 2 in case of already reserved ID - that is almost twice as much > >processor time > >that may count much if the routine is used frequently > > Go ahead, try it, and tell me how much time it cost. it would be an interesting benchmark, timing it on some 10 runs or like that, if I'll have some time I promise I'll do it :) > > From experience, there are things one can spend > their time optimizing and there are other things > that one should be able to see that aren't worth > pursing. yes, it's true. as for the current thing, I do not have experience or benchmarks, so you may be right that it does not worth the energy. I said what I said out of logic, which says that 2 queries are slower than 1 query ;) > > I've been wrong before, but you're open to prove me wrong again, if you like. when I'll have some free time (probably not in the next couple of weeks...) I think I'll try to benchmark it - and we'll see whether the difference is worth mentioning or not :) but if anyone has (or you have) existing benchmarks please show me, I'm interested in it greets Zoltán Németh > > Cheers, > > tedd > -- > --- > http://sperling.com http://ancientstones.com http://earthstones.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: > As for efficiency, that's probably not even worth mentioning in this case. why not? you would use 2 sql queries while I would use one most of the time and 2 in case of already reserved ID - that is almost twice as much processor time that may count much if the routine is used frequently Go ahead, try it, and tell me how much time it cost. From experience, there are things one can spend their time optimizing and there are other things that one should be able to see that aren't worth pursing. I've been wrong before, but you're open to prove me wrong again, if you like. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: > At 4:28 PM +0100 3/22/07, Németh Zoltán wrote: > >2007. 03. 22, csütörtök keltezéssel 11.24-kor tedd ezt írta: > >> At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: > >> >Hello, > >> >I want to add a random unique ID to a Mysql table. Collisions > >> >are unlikely but possible so to handle those cases I'd like to > >> >regenerate the random ID until there is no collision and only > >> >then add my row. Any suggestions for a newbie as to the right > >> >way to go about doing this? > >> >Best, > >> >Craig > >> > >> Craig: > >> > >> Simple. > >> > >> Generate a "random unique ID" via whatever method you want. However, > >> before using, search your dB to see if it's already in use. If it is, > >> then generate another one and repeat. > > > >it's probably more efficient to try to insert with the generated ID at > >once, and repeat only if it fails. > >if the ID generation method is good enough, repeat will be needed only > >extremely rarely > > > >greets > >Zoltán Németh > > > I like to write code that avoids failure if > possible rather than writing something that I > know can fail and then dealing with resultant > errors. Just differences in perspectives. that's a matter of taste, which can not be argued ;) > > As for efficiency, that's probably not even worth mentioning in this case. why not? you would use 2 sql queries while I would use one most of the time and 2 in case of already reserved ID - that is almost twice as much processor time that may count much if the routine is used frequently greets Zoltán Németh > > Cheers, > > tedd > -- > --- > http://sperling.com http://ancientstones.com http://earthstones.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
At 4:28 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.24-kor tedd ezt írta: At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: >Hello, >I want to add a random unique ID to a Mysql table. Collisions >are unlikely but possible so to handle those cases I'd like to >regenerate the random ID until there is no collision and only >then add my row. Any suggestions for a newbie as to the right >way to go about doing this? >Best, >Craig Craig: Simple. Generate a "random unique ID" via whatever method you want. However, before using, search your dB to see if it's already in use. If it is, then generate another one and repeat. it's probably more efficient to try to insert with the generated ID at once, and repeat only if it fails. if the ID generation method is good enough, repeat will be needed only extremely rarely greets Zoltán Németh I like to write code that avoids failure if possible rather than writing something that I know can fail and then dealing with resultant errors. Just differences in perspectives. As for efficiency, that's probably not even worth mentioning in this case. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
2007. 03. 22, csütörtök keltezéssel 11.24-kor tedd ezt írta: > At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: > >Hello, > >I want to add a random unique ID to a Mysql table. Collisions > >are unlikely but possible so to handle those cases I'd like to > >regenerate the random ID until there is no collision and only > >then add my row. Any suggestions for a newbie as to the right > >way to go about doing this? > >Best, > >Craig > > Craig: > > Simple. > > Generate a "random unique ID" via whatever method you want. However, > before using, search your dB to see if it's already in use. If it is, > then generate another one and repeat. it's probably more efficient to try to insert with the generated ID at once, and repeat only if it fails. if the ID generation method is good enough, repeat will be needed only extremely rarely greets Zoltán Németh > > Cheers, > > tedd > -- > --- > http://sperling.com http://ancientstones.com http://earthstones.com > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? Best, Craig Craig: Simple. Generate a "random unique ID" via whatever method you want. However, before using, search your dB to see if it's already in use. If it is, then generate another one and repeat. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
function GenerateID () { $len = 3; $base='ABCDEFGHKLMNOPQRSTWXYZ'; $max=strlen($base)-1; $activatecode=''; mt_srand((double)microtime()*100); while (strlen($activatecode)<$len+1)$activatecode.=$base{mt_rand(0,$max)}; $len = 7; $base='1234567890'; $max=strlen($base)-1; mt_srand((double)microtime()*100); while (strlen($activatecode)<$len+1) $activatecode.=$base{mt_rand(0,$max)}; return $activatecode; } this will generate and ID of 4 letters and 4 digits based on the current time stamp.. ex: *QCKS9046 ...* the possibility of generating the same ID again is almost 0... (and you can make it even less if you increase the length)... PS: I don't take credit for the code as it is a modified version of a code I found long time back (this same code is running on one of my applications for months without any problem).. Regards, Rabih G. Tayyem On 3/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743&co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Unique ID
[EMAIL PROTECTED] wrote: I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? 1) Not even slightly PHP related. 2) Why random? Incrementing not good enough for you? -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] random selection from each subfolder
On 12/22/06, Steven Macintyre <[EMAIL PROTECTED]> wrote: Ok ... previous problem sorted ... now onto the next ... The client wants the following; A scroll bar with 3 random thumbs from each subdirectory in the /images/ folder I was thinking ... Going into each folder, getting files, pushing into an array - shuffling array, taking first three items and combine it to a "master" array and use that ... As you get more & more images this will slow down, might take a while but it will happen eventually. Are you storing any info about images in a database (even just the name and folder they appear in) ? You could use that to your advantage.. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random pictures - not twice
- Original Message - From: "tedd" <[EMAIL PROTECTED]> To: "Gustav Wiberg" <[EMAIL PROTECTED]>; "PHP General" Sent: Monday, December 04, 2006 4:15 PM Subject: Re: [PHP] Random pictures - not twice At 11:20 PM +0100 12/3/06, Gustav Wiberg wrote: Hi there! I have created a script the generates random pictures... -snip- With this above script the same picture can be shown twice. Is there any smart way of avoiding this without having to rely on cookies/sessionids? Random does mean it can happen more than once. I think what you want is more along a shuffle. Look into the array function "shuffle". Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi there! Ok, thanx! I will check the function out :-) Best regards Gsutav Wiberg http://www.stammis.com/ - Stammis Internet - pedigrees on the net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random pictures - not twice
At 11:20 PM +0100 12/3/06, Gustav Wiberg wrote: Hi there! I have created a script the generates random pictures... -snip- With this above script the same picture can be shown twice. Is there any smart way of avoiding this without having to rely on cookies/sessionids? Random does mean it can happen more than once. I think what you want is more along a shuffle. Look into the array function "shuffle". Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random pictures - not twice
- Original Message - From: <[EMAIL PROTECTED]> To: Cc: <[EMAIL PROTECTED]> Sent: Sunday, December 03, 2006 11:52 PM Subject: Re: [PHP] Random pictures - not twice Without using cookies or session information, you're going to go through your picture list faster depending on how many users are accessing the random pic page. If you don't make it user-specific, then it doesn't really matter if you go through the images sequentially.. it may appear random on the user end because other users are going to be grabbing sequential pics as well. If you want to stir the waters a bit, you could run them sequentially but randomize the sequence. This is what some music playlist programs do when you randomize a playlist. Instead of pulling a random song from the list and risking playing the same song back to back, it just shuffles the playlist and plays it sequentially. When you get to the end of your randomized list, you can re-shuffle it and start over. This gives some semblance of randomness. If you want to make sure each image gets its fair amount of time in the spotlight, you could keep track of how many times each image has been displayed. Having a database table with a list of all the image names and their 'served' count would let you weight your list a bit to give preference to the images that havn't been displayed that often. And if you want to give each user the total package, you can keep track of how many times each image was served to a specific user and weight your shuffling that way. I'm sure there are other ways, but there are just a few that may be viable for you, depending on the level of randomness per user you need. Let us know what solution you come up with. I'm sure others have had similar questions and just havn't asked. -TG = = = Original message = = = Hi there! I have created a script the generates random pictures... With this above script the same picture can be shown twice. Is there any smart way of avoiding this without having to rely on cookies/sessionids? Best regards /Gustav Wiberg Stammis Internet - http://www.stammis.com/ - pedigrees on the net ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi again! I've solved it with array_rand. It wasn't that hard at all, just had to know which function to use! :-) code: Best regards /Gustav Wiberg Stammis Internet - http://www.stammis.com/ - pedigrees on the net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random pictures - not twice
Without using cookies or session information, you're going to go through your picture list faster depending on how many users are accessing the random pic page. If you don't make it user-specific, then it doesn't really matter if you go through the images sequentially.. it may appear random on the user end because other users are going to be grabbing sequential pics as well. If you want to stir the waters a bit, you could run them sequentially but randomize the sequence. This is what some music playlist programs do when you randomize a playlist. Instead of pulling a random song from the list and risking playing the same song back to back, it just shuffles the playlist and plays it sequentially. When you get to the end of your randomized list, you can re-shuffle it and start over. This gives some semblance of randomness. If you want to make sure each image gets its fair amount of time in the spotlight, you could keep track of how many times each image has been displayed. Having a database table with a list of all the image names and their 'served' count would let you weight your list a bit to give preference to the images that havn't been displayed that often. And if you want to give each user the total package, you can keep track of how many times each image was served to a specific user and weight your shuffling that way. I'm sure there are other ways, but there are just a few that may be viable for you, depending on the level of randomness per user you need. Let us know what solution you come up with. I'm sure others have had similar questions and just havn't asked. -TG = = = Original message = = = Hi there! I have created a script the generates random pictures... With this above script the same picture can be shown twice. Is there any smart way of avoiding this without having to rely on cookies/sessionids? Best regards /Gustav Wiberg Stammis Internet - http://www.stammis.com/ - pedigrees on the net ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] random string
You have an array of names and you want to choose a random name. is it? try thinking some thing about arrays, keys numbers, key count, and such Ross wrote: > > > Hi, > > I want to randomise a string > > $myrandom = rand("ross", "andrea"); > > echo $myrandom; > > > I know this doesn't work but is there a built in function to do this? > > > R. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- View this message in context: http://www.nabble.com/random-string-tf2459193.html#a6881109 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] random string
On Tue, October 17, 2006 7:30 am, Ross wrote: > I want to randomise a string > > $myrandom = rand("ross", "andrea"); > > echo $myrandom; > > I know this doesn't work but is there a built in function to do this? I'm not real clear on what "this" is... Choose a string at random from an array? $possibles = array('ross', 'andrea'); shuffle($possibles); echo $possibles[0]; Or are you trying to compose a new string of randomly-selected characters of a bunch of other strings? Some combination of these functions might be in the recipe: http://php.net/mt_rand http://php.net/shuffle http://php.net/explode -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] random string
On 10/17/06, Ross <[EMAIL PROTECTED]> wrote: Hi, I want to randomise a string $myrandom = rand("ross", "andrea"); I suggest : $array_name = array("rose","andrea"); $myrandom = array_rand($array_name); echo $myrandom[0]; Brice. I know this doesn't work but is there a built in function to do this? R. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Random value from ini file
> I have an ini file that has: > 1 = "words"; > 2 = "words1"; > 3 = "words3"; > > I want to pull a rand value and print it out > I'm trying to use parse_ini_file but its not working any help would > be great. > Thanks You could read them all into an array then use array_rand() to pick one. http://us2.php.net/manual/en/function.array-rand.php JM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random permission strangeness
On Fri, 2006-03-10 at 16:00 +1100, Chris wrote: > If you can produce a small test case might be time for a bug report. It > shouldn't give you "permission denied" errors. > Will work on it over the weekend. I am going to try something dead simple with the session stuff and see what I can do with it. If that also fails, will do the bug report, but I want to be dead sure before I start causing trouble for other people! Thanks for your help! --Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random permission strangeness
Paul Scott wrote: On Fri, 2006-03-10 at 10:26 +1100, Chris wrote: If you leave your browser open for 20 mins or something and then try to log in, does that replicate it? Ah hah! The plot thickens! It seems that I can: 1. Launch the app - thereby starting the initial session 2. Leave the session to time out 3. Log in - adding username and permissions to the *non-existant session*! 4. Log out and voila! error. So it seems that the session is timing out somewhere along the line, and when it is going to be re-established, it can't because a fragment(?) of it still kinda exists - in comes the error regarding cleanup of files. If you can produce a small test case might be time for a bug report. It shouldn't give you "permission denied" errors. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random permission strangeness
On Fri, 2006-03-10 at 10:26 +1100, Chris wrote: > If you leave your browser open for 20 mins or something and then try to > log in, does that replicate it? > Ah hah! The plot thickens! It seems that I can: 1. Launch the app - thereby starting the initial session 2. Leave the session to time out 3. Log in - adding username and permissions to the *non-existant session*! 4. Log out and voila! error. So it seems that the session is timing out somewhere along the line, and when it is going to be re-established, it can't because a fragment(?) of it still kinda exists - in comes the error regarding cleanup of files. --Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random permission strangeness
Paul Scott wrote: On Thu, 2006-03-09 at 16:05 +1100, Chris wrote: What's the whole error message (ie context)? Is it coming from cron or randomly in your scripts? From Xdebug... Its random. I am just thinking though that what it *might* be is that the initial session is timing out between the app launch and the user logging in. I start the session beforehand, and simply add/delete from it as the user moves through the system. Notice: session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 967 If you leave your browser open for 20 mins or something and then try to log in, does that replicate it? My first guess is garbage collection.. What are the permissions on that folder? If it's randomly in your scripts, which user is your webserver running as? www-data, permissions are drwx-wx-wt owner root. Would it not be a little unsafe to change those permissions to anything less secure? I certainly wouldn't think it OK to chown to the webserver user...? Should be ok to leave it as it is. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random permission strangeness
On Thu, 2006-03-09 at 16:05 +1100, Chris wrote: > What's the whole error message (ie context)? Is it coming from cron or > randomly in your scripts? >From Xdebug... Its random. I am just thinking though that what it *might* be is that the initial session is timing out between the app launch and the user logging in. I start the session beforehand, and simply add/delete from it as the user moves through the system. Notice: session_start() [function.session-start]: ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 967 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->__construct() /var/www/5ive/app/index.php:26 3 engine->sessionStart() /var/www/5ive/app/classes/core/engine_class_inc.php:236 4 session_start () /var/www/5ive/app/classes/core/engine_class_inc.php:967 Warning: Cannot modify header information - headers already sent by (output started at /var/www/5ive/app/classes/core/engine_class_inc.php:967) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 1060 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->run() /var/www/5ive/app/index.php:31 3 engine->_dispatch() /var/www/5ive/app/classes/core/engine_class_inc.php:296 4 header () /var/www/5ive/app/classes/core/engine_class_inc.php:1060 Warning: Cannot modify header information - headers already sent by (output started at /var/www/5ive/app/classes/core/engine_class_inc.php:967) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 1061 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->run() /var/www/5ive/app/index.php:31 3 engine->_dispatch() /var/www/5ive/app/classes/core/engine_class_inc.php:296 4 header () /var/www/5ive/app/classes/core/engine_class_inc.php:1061 Warning: Cannot modify header information - headers already sent by (output started at /var/www/5ive/app/classes/core/engine_class_inc.php:967) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 1062 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->run() /var/www/5ive/app/index.php:31 3 engine->_dispatch() /var/www/5ive/app/classes/core/engine_class_inc.php:296 4 header () /var/www/5ive/app/classes/core/engine_class_inc.php:1062 Warning: Cannot modify header information - headers already sent by (output started at /var/www/5ive/app/classes/core/engine_class_inc.php:967) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 1063 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->run() /var/www/5ive/app/index.php:31 3 engine->_dispatch() /var/www/5ive/app/classes/core/engine_class_inc.php:296 4 header () /var/www/5ive/app/classes/core/engine_class_inc.php:1063 Warning: Cannot modify header information - headers already sent by (output started at /var/www/5ive/app/classes/core/engine_class_inc.php:967) in /var/www/5ive/app/classes/core/engine_class_inc.php on line 1064 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->run() /var/www/5ive/app/index.php:31 3 engine->_dispatch() /var/www/5ive/app/classes/core/engine_class_inc.php:296 4 header () /var/www/5ive/app/classes/core/engine_class_inc.php:1064 Warning: Cannot modify header information - headers already sent by (output started at /var/www/5ive/app/classes/core/engine_class_inc.php:967) in /var/www/5ive/app/templates/page/default_page_tpl.php on line 1 Call Stack # Function Location 1 {main}() /var/www/5ive/app/index.php:0 2 engine->run() /var/www/5ive/app/index.php:31 3 engine->_callTemplate() /var/www/5ive/app/classes/core/engine_class_inc.php:309 4 controller->callTemplate() /var/www/5ive/app/classes/core/engine_class_inc.php:1153 5 require() /var/www/5ive/app/classes/core/controller_class_inc.php:255 6 header () /var/www/5ive/app/templates/page/default_page_tpl.php:1 > > My first guess is garbage collection.. > > What are the permissions on that folder? If it's randomly in your > scripts, which user is your webserver running as? www-data, permissions are drwx-wx-wt owner root. Would it not be a little unsafe to change those permissions to anything less secure? I certainly wouldn't think it OK to chown to the webserver user...? --Paul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random permission strangeness
Paul Scott wrote: I am pretty much randomly getting the following error: .. ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in ... As far as I can see the session write directory has no problems with permissions. The *really* strange thing is that it only fails at certain times, and nothing really reproduceable. I am using: PHP Version 5.1.2 on Apache2 Debian GNU/Linux amd64 stock kernel on Opteron processors. What's the whole error message (ie context)? Is it coming from cron or randomly in your scripts? My first guess is garbage collection.. What are the permissions on that folder? If it's randomly in your scripts, which user is your webserver running as? -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Images with no duplicates?
"Mike" <[EMAIL PROTECTED]> wrote in message news:... I'd just like to thank everyone who helped me our with this. I think it's great that so many people would be so helpful and not expect anything in return. This list is quite a storehouse of info and I'm learning just from reading the posts since I joined last week! Again, thanks all. -Mike > ""Kilbride, James"" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > Actually with this idea all you do is reduce $max after each successful > pull and 'increment' over pictures you already have. That way you never > have to pull another random number. You just may have to increment > through the entire set of pulled images if you pulled a high enough > number. > > for($i = 0; $i < $want; $i++) { > $random = mt_rand(0,$max); > for($j = 0; $j < $i; $j++) { > if ($retrieved[$j] < $random) { > $random++; > } > } > $retrieved[] = $random; > sort($retrieved); > $max--; > } > > Guarentees unique choices. > > > >> > I'm still very green with PHP, but am working to fix that. >> > >> > I've searched high and low for an answer to this question >> and so far >> > no solution has presented itself. I have a script to >> populate my web >> > page with random images: >> > >> > > > #random images example >> > #this is your file >> > $file = "images.txt"; >> > #open the file >> > $openFile = file($file); >> > #generate a random number >> > srand((double)microtime()*100); >> > #get one of the entries in the file >> > $random_image = $openFile[array_rand($openFile)]; #display >> the entry >> > echo ""; ?> >> > >> > >> > This works beautifully, but my problem is that sometimes, >> the same image >> > displays twice or more on the same page-load. My page >> requires 10 different >> > places where my images need to load, but I can't have any >> duplicate images >> > show up. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Images with no duplicates?
I'd just like to thank everyone who helped me our with this. I think it's great that so many people would be so helpful and not expect anything in return. This list is quite a storehouse of info and I'm learning just from reading the posts since I joined last week! Again, thanks all. -Mike ""Kilbride, James"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Actually with this idea all you do is reduce $max after each successful pull and 'increment' over pictures you already have. That way you never have to pull another random number. You just may have to increment through the entire set of pulled images if you pulled a high enough number. for($i = 0; $i < $want; $i++) { $random = mt_rand(0,$max); for($j = 0; $j < $i; $j++) { if ($retrieved[$j] < $random) { $random++; } } $retrieved[] = $random; sort($retrieved); $max--; } Guarentees unique choices. > > I'm still very green with PHP, but am working to fix that. > > > > I've searched high and low for an answer to this question > and so far > > no solution has presented itself. I have a script to > populate my web > > page with random images: > > > > > #random images example > > #this is your file > > $file = "images.txt"; > > #open the file > > $openFile = file($file); > > #generate a random number > > srand((double)microtime()*100); > > #get one of the entries in the file > > $random_image = $openFile[array_rand($openFile)]; #display > the entry > > echo ""; ?> > > > > > > This works beautifully, but my problem is that sometimes, > the same image > > displays twice or more on the same page-load. My page > requires 10 different > > places where my images need to load, but I can't have any > duplicate images > > show up. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Images with no duplicates?
Silvio Porcellana [tradeOver] wrote: > > > $file = "images.txt"; > $openFile = file($file); > $num_images = 10; > # don't need this is PHP > 4.2.0 > srand((float) microtime() * 1000); > $random_keys = array_rand($openFile, $num_images); > foreach ($random_keys as $random_key) { > echo " width='100'>"; ops, sorry, that obviously should be: echo ""; > } > Sorry about this! Silvio -- tradeOver | http://www.tradeover.net ...ready to become the King of the World? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Images with no duplicates?
Jared Williams wrote: > Hi, > Just unset the ones you've picked > > #random images example > #this is your file > $file = "images.txt"; > #open the file > $openFile = file($file); > #generate a random number > srand((double)microtime()*100); > #get one of the entries in the file > for ($i = 0; $i < 10; ++$i) > { >$r = array_rand($openFile); >$random_image = $openFile[$r]; >echo ""; >unset($openFile[$r]); > } > ?> > > Jared > Sorry if I jump in late in this thread, but wouldn't this work? $file = "images.txt"; $openFile = file($file); $num_images = 10; # don't need this is PHP > 4.2.0 srand((float) microtime() * 1000); $random_keys = array_rand($openFile, $num_images); foreach ($random_keys as $random_key) { echo ""; } array_rand: http://php.net/array_rand Maybe I'm missing something... Anyway, cheers everybody! Silvio -- tradeOver | http://www.tradeover.net ...ready to become the King of the World? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Random Images with no duplicates?
Hi, Just unset the ones you've picked "; unset($openFile[$r]); } ?> Jared -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Random Images with no duplicates?
Actually with this idea all you do is reduce $max after each successful pull and 'increment' over pictures you already have. That way you never have to pull another random number. You just may have to increment through the entire set of pulled images if you pulled a high enough number. for($i = 0; $i < $want; $i++) { $random = mt_rand(0,$max); for($j = 0; $j < $i; $j++) { if ($retrieved[$j] < $random) { $random++; } } $retrieved[] = $random; sort($retrieved); $max--; } Guarentees unique choices. > -Original Message- > From: Curt Zirzow [mailto:[EMAIL PROTECTED] > Sent: Friday, December 16, 2005 2:47 AM > To: php-general@lists.php.net > Subject: Re: [PHP] Random Images with no duplicates? > > On Thu, Dec 15, 2005 at 08:45:33PM -0800, Mike Rondeau wrote: > > Hi, > > > > I'm still very green with PHP, but am working to fix that. > > > > I've searched high and low for an answer to this question > and so far > > no solution has presented itself. I have a script to > populate my web > > page with random images: > > > > > #random images example > > #this is your file > > $file = "images.txt"; > > #open the file > > $openFile = file($file); > > #generate a random number > > srand((double)microtime()*100); > > #get one of the entries in the file > > $random_image = $openFile[array_rand($openFile)]; #display > the entry > > echo ""; ?> > > > > > > This works beautifully, but my problem is that sometimes, > the same image > > displays twice or more on the same page-load. My page > requires 10 different > > places where my images need to load, but I can't have any > duplicate images > > show up. > > Depending on the complexity of the logic you want in selecting > random images you can do something like: > > $files = file($file); > > $want = 10;// how many I want > $max = count($files); // the range, we might need -1 > > // a simple range check, to avoid an infinate loop > $can_have = $want > $max? $max: $want; > > // start off the loop with these values > $have = 0; // aka have none > $images = array(); // aka no random images > > do { > // generate a random number > $random = mt_rand(0, $max); > > // if we dont have it.. > if(! isset($images[$random]) ) { > $have++; > $images[$random] = $files[$random]; > } > > // have we made it there yet? > } while($have < $can_have) > > var_dump($images); > > foreach($images as $random_image) { > echo ""; > } > > Now, keep in mind that if you have 15 images and you want 10, this > could potentially be very intensive on the cpu. > > On the other hand if you have 10,000 images and are looking for 10 > it wont be as intensive on the cpu, but will use a lot of memory > that really shouldn't be used by loading the file into an array. At > this point an index file should be used or a DB solution should be > considered. > > > Curt. > -- > cat .signature: No such file or directory > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Images with no duplicates?
On Thu, Dec 15, 2005 at 08:45:33PM -0800, Mike Rondeau wrote: > Hi, > > I'm still very green with PHP, but am working to fix that. > > I've searched high and low for an answer to this question and so far > no solution has presented itself. I have a script to populate my web page > with random images: > > #random images example > #this is your file > $file = "images.txt"; > #open the file > $openFile = file($file); > #generate a random number > srand((double)microtime()*100); > #get one of the entries in the file > $random_image = $openFile[array_rand($openFile)]; > #display the entry > echo ""; > ?> > > > This works beautifully, but my problem is that sometimes, the same image > displays twice or more on the same page-load. My page requires 10 different > places where my images need to load, but I can't have any duplicate images > show up. Depending on the complexity of the logic you want in selecting random images you can do something like: $files = file($file); $want = 10;// how many I want $max = count($files); // the range, we might need -1 // a simple range check, to avoid an infinate loop $can_have = $want > $max? $max: $want; // start off the loop with these values $have = 0; // aka have none $images = array(); // aka no random images do { // generate a random number $random = mt_rand(0, $max); // if we dont have it.. if(! isset($images[$random]) ) { $have++; $images[$random] = $files[$random]; } // have we made it there yet? } while($have < $can_have) var_dump($images); foreach($images as $random_image) { echo ""; } Now, keep in mind that if you have 15 images and you want 10, this could potentially be very intensive on the cpu. On the other hand if you have 10,000 images and are looking for 10 it wont be as intensive on the cpu, but will use a lot of memory that really shouldn't be used by loading the file into an array. At this point an index file should be used or a DB solution should be considered. Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random Images with no duplicates?
This should work, although if there are only 9 lines in the file, it will run infintely (or until the page times out)... so put a check in for that. $imagesNeeded = 10; $imageArr = array(); // Create array with $imagesNeeded number of elements. for($i=0;$i<$imagesNeeded;$i++) { // choose image $tmpImg = $openFile[array_rand($openFile)]; // Keep getting images until the image you have is not in the existing array of images while(in_array($tmpImg,$imagesArr)) { // choose image $tmpImg = $openFile[array_rand($openFile)]; } // Put unique image into array array_push($imageArr,$tmpImg); } // You now have an array called imageArr with 10 elements/images in it. Aaron On 12/15/05, Mike Rondeau <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm still very green with PHP, but am working to fix that. > > I've searched high and low for an answer to this question and so far > no solution has presented itself. I have a script to populate my web page > with random images: > > #random images example > #this is your file > $file = "images.txt"; > #open the file > $openFile = file($file); > #generate a random number > srand((double)microtime()*100); > #get one of the entries in the file > $random_image = $openFile[array_rand($openFile)]; > #display the entry > echo ""; > ?> > > > This works beautifully, but my problem is that sometimes, the same image > displays twice or more on the same page-load. My page requires 10 > different > places where my images need to load, but I can't have any duplicate images > show up. > > Any suggestions on what I need to modify here? > > Thanks in advance! > Mike > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] random row
On Wed, Nov 16, 2005 at 05:19:52PM +1300, Jasper Bryant-Greene wrote: > John Taylor-Johnston wrote: > >My question is simnple. I want to randomly select a row in a mysql > >table. I have a primary id. > > > > >$server = "localhost"; > >$user = "foo"; > >$pass = "foo"; > >$db="foo_db"; > >$table="foo_table"; > >$myconnection = mysql_connect($server,$user,$pass); > >mysql_select_db($db,$myconnection); > > > >$sql = ??; > > > >$news = mysql_query($sql) or die(print " >color=red>".mysql_error().""); > > while ($mydata = mysql_fetch_object($news)) > > { > >?? > > } > >?> > > > > If your table isn't too big, it's fine to do: > > SELECT * FROM mytable ORDER BY RAND() LIMIT 1 > > If you've got more than a few 10,000s of rows, you might want to look at > other ways, like selecting a random row based on the primary key by > generating a random number in PHP before executing the SQL. Very good idea on the 10,000+ rows, if you are dealing with large tables order by rand() isn't very wise, there is one catch though with using a random value from php. Assuming you have a auto_increment for the primary key named 'id': the first thing you need to do is get the max value of it: select max(id) from table That isn't the catch, that query should be quicker than ~.0002 seconds or so :) The problem is you have to account for any deleted records: $min = 1; // mysql first auto_increment list($max) = mysql_fetch_row(mysql_query("select max(id) from table")); do { $rand = mt_rand($min, $max); $row = mysql_query("select * from table where id = $rand"); if(mysql_errno() ) { break; // fook me. } } while(! $row); if ($row) { // we have a quick random row. } Depending on the space between deleted records, this most likely would be more resource friendly (on large tables) than havning mysql sort all the records to some tmp table (on disk) then sending only the first record. HTH, Curt. -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] random row
John Taylor-Johnston wrote: My question is simnple. I want to randomly select a row in a mysql table. I have a primary id. $news = mysql_query($sql) or die(print "color=red>".mysql_error().""); while ($mydata = mysql_fetch_object($news)) { ?? } ?> If your table isn't too big, it's fine to do: SELECT * FROM mytable ORDER BY RAND() LIMIT 1 If you've got more than a few 10,000s of rows, you might want to look at other ways, like selecting a random row based on the primary key by generating a random number in PHP before executing the SQL. Jasper -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random but ordered..
Check the MySQL manual for how to order randomly. They might have a way to do it. However... If there are a fairly number of consistent plans in each company, you might be better off with something that just chooses N companies at random, enough to fill a page, and that's it. One wrinkle is this: If user X goes forward a page, can they see the same company again, or does the order need to be fixed after they see page 1? If it must be fixed, I think you'd be best served with making a @TEMP table in MySQL and then assigning each company ID a random place in it, and using that as your ordering for company IDs. On Sat, May 7, 2005 5:52 am, Ryan A said: > Hey, > > I have been screwing around with this code for around a day and am hitting > a > wall, any > help would be appreciated. > > > Basically, I am working on a site that queries the DB for companies and > the > plans the company > is offering, the DB is quite big (a few thousand records in each of the 20 > tables) > > The parameters are taken from the client in the form of a search box and > usually gives around 1000 results per query, they results are then > displayed > like this: > > > company 1 > [] plan > [] plan > [] plan > [] plan > company 2 > [] plan > [] plan > [] plan > company 3 > [] plan > company 4 > [] plan > [] plan > > So far, no problems (even though the code and the design are mixed > together > in the page) > but so far the code is getting the results grouping via $cno, which > results > in the lowest being displayed first which gives the first companies who > joined an edge as they are always getting displayed. > > > Heres the kicker, he wants to have the same display as abovebut > randomly > from the DB *while still* having pagination.. so new joined companies too > get displayed and not shoved at the end of the results. > > > To see the code used presently (stripped down to a few lines) : > http://jappz.com/testing.phpp > > To see the output from the above : > http://jappz.com/testing.html > > > Any suggestions, classes, code, links or general help would be > appreciated. > > Thanks, > Ryan > > > > -- > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.308 / Virus Database: 266.11.6 - Release Date: 5/6/2005 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random but ordered..
Ryan A wrote: Hey, I have been screwing around with this code for around a day and am hitting a wall, any help would be appreciated. Basically, I am working on a site that queries the DB for companies and the plans the company is offering, the DB is quite big (a few thousand records in each of the 20 tables) The parameters are taken from the client in the form of a search box and usually gives around 1000 results per query, they results are then displayed like this: company 1 [] plan [] plan [] plan [] plan company 2 [] plan [] plan [] plan company 3 [] plan company 4 [] plan [] plan So far, no problems (even though the code and the design are mixed together in the page) but so far the code is getting the results grouping via $cno, which results in the lowest being displayed first which gives the first companies who joined an edge as they are always getting displayed. Heres the kicker, he wants to have the same display as abovebut randomly from the DB *while still* having pagination.. so new joined companies too get displayed and not shoved at the end of the results. Choices: 1. ORDER_BY RAND(), and keep the full result set (or just the ids) in session 2. add another column, display_order, and update it at regular intervals to random values. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random data loss.
I think I need to give more details. The data loss happens somewhere between the form post button press and the data being inserted into the DB. It is a simple sql insert statement on a table with auto increment keys. The price should be entered as a floating point number and that is what my user who had the problem happen did. 34.72 in one case. The price that ended up in the DB was zero. I tried to see if maybe there was a mistake by putting in two periods but that just makes it store 34.00 instead. I tried spaces around the numbers and that didn't have any effect. In every case where this has happened the user was able to use the web form for modifying the data and changed the price back, post the form which then executes an update sql statement and that corrected the data. The only thing I can think might be the cause is the data is actually stored in 2 tables. The first table, "Gift", stores the basic information about the Gift you want and the second table, "Vendor", stores the information about where to get it as well as the price. I am including the the queries below. A quick not the Gift table is a double key table on UserKey and GiftKey and the Vendor table is a triple key table on UserKey, GiftKey and VendorKey. It was set up this way to allow a one to many relationship between Gift and Vendor, however at this time the relationship is always a one to one. $query = "INSERT INTO Gift Values \n('$UserKey', NULL, '$Description', '$Qty', '0',\n"; $query .= "'$Manufacturer', '$ModelNum', '$InfoURL', '$ImageURL', '$Category',\n"; $query .= "'$Priority', '$AddDate', '$ExpireDate'\n)"; $result = mysql_query($query); if(! $result){ $ErrorMsg = "I'm sorry, there was a database error, please try again later.\n" . mysql_error(); include 'AddGiftForm.php'; exit; } $GiftKey = mysql_insert_id($link); $query1 = "INSERT INTO Vendor Values \n('$UserKey', '$GiftKey', NULL, '$Price', '$VName', '$VURL',\n"; $query1 .= "'$VStreetAddress', '$VCity', '$VState', '$VZIP', '$Phone')"; $result = mysql_query($query1); if(! $result){ $ErrorMsg = "I'm sorry, there was a database error, please try again later.\n" . mysql_error(); include 'AddGiftForm.php'; exit; } Chris W Gift Giving Made Easy Get the gifts you want & give the gifts they want this holiday season http://thewishzone.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random data loss.
2wsxdr5 wrote: > With out posting any code I was wondering if anyone here has been > experiencing this kind of problem. I have a standard web from that PHP > code then reads and saves the data into a MySQL DB. The problem is some > of my users have had data lost somewhere in this process. The web site > is www.thewishzone.com. It is a wish list site and the data that seems > to be getting lost is the price of an item a user adds to their wish > list. I can't seem to duplicate it here. However one user did have it > happen twice in a short time period. They enter a valid price and after > the record posts the price goes to zero. Any ideas? How do you determine a valid price? Do you allow the $ to be in it? Cuz MySQL sure won't take that. Very common mistake. Are you checking mysql result for error in your INSERT and UPDATE statements. MySQL should not be losing data without SOME kind of message... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random data loss.
2wsxdr5 wrote: With out posting any code I was wondering if anyone here has been experiencing this kind of problem. I have a standard web from that PHP code then reads and saves the data into a MySQL DB. The problem is some of my users have had data lost somewhere in this process. The web site is www.thewishzone.com. It is a wish list site and the data that seems to be getting lost is the price of an item a user adds to their wish list. I can't seem to duplicate it here. However one user did have it happen twice in a short time period. They enter a valid price and after the record posts the price goes to zero. Any ideas? pretty hard to tell with this information. What you might want to do, is to call the error_log() function with the insert query that is being executed. That way you will have a record of each query that has been executed. (if you have a software that can analyse your mysql binary log, it could serve the same purpose). You could then look at these queries to see if there is anything suspicious. You could also have a bit of code that tests the value of the price variable in each page and mail you all the env settings if price happens to be zero that way you would have a chance of reproducing the problem. Chris W Gift Giving Made Easy Get the gifts you want & give the gifts they want this holiday season http://thewishzone.com -- Raditha Dissanayake. -- http://www.radinks.com/print/card-designer/ | Card Designer Applet http://www.radinks.com/upload/ | Drag and Drop Upload -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Random data loss.
Could be a problem of multiple update modules for the same table. When I've encountered this problem in the past it's been one of two causes. 1. In the process of maintaining the table one routine that has no price information, retrieves the row and notices that the something needs to be changed, and instead of only updating columns that have changed it seeks to update all of them (perhaps satisfying one programmers sense of order), and since it has no price info, it replaces the price with zero (good rule IMHO; only update columns that you know need to be changed). 2. Update queries that did not specify all the appropriate where clauses, thereby updating multiple rows, and perhaps in this case updating with zero prices (perhaps contributed to by coding all elements as above). (a rule that I apply to myself, not necessarily quite as good as the previous rule, use artificial keys [auto increment fields] and update with unique [or a list of] artificial key in the where clause). One nice thing about auto increment primary keys is they are self locking in that no two insert rows can get the same artificial key, even if the insert occurs at the same time (at least in MySQL). Take a look at the text in your actual queries and read them over and over, the answer is there. Don't consider this an exhaustive list, there are lots of people out there more clever than I coming up with new ways to loose data every day. But this is where I would start. Hope this helps, Warren Vail > -Original Message- > From: 2wsxdr5 [mailto:[EMAIL PROTECTED] > Sent: Monday, December 06, 2004 4:27 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Random data loss. > > > With out posting any code I was wondering if anyone here has been > experiencing this kind of problem. I have a standard web > from that PHP > code then reads and saves the data into a MySQL DB. The > problem is some > of my users have had data lost somewhere in this process. > The web site > is www.thewishzone.com. It is a wish list site and the data > that seems > to be getting lost is the price of an item a user adds to their wish > list. I can't seem to duplicate it here. However one user > did have it > happen twice in a short time period. They enter a valid > price and after > the record posts the price goes to zero. Any ideas? > > Chris W > > Gift Giving Made Easy > Get the gifts you want & give the > gifts they want this holiday season > http://thewishzone.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php