440,963 Members | 1,749 Online
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

Pick 5 random entrys

 P: n/a What is wrong with this php code ? . (it works fine - but something that just works isnt good enough for this newsgroup is it) 55) {break;} if (\$loopy>222) {\$kon="break";} \$loopy=\$loopy+1; } sort(\$kirk); \$kirk=array_keys(array_flip(\$kirk)); \$loopy=0; while (\$loopy<5) { \$bones=\$kirk[\$loopy]; if (\$bones<>"") {include('display_entry.php');} \$loopy=\$loopy+1; } ?> Aug 6 '08 #1
36 Replies

 P: n/a On Aug 6, 8:08*pm, Krustov 55) {break;} if (\$loopy>222) {\$kon="break";} \$loopy=\$loopy+1; } sort(\$kirk); \$kirk=array_keys(array_flip(\$kirk)); \$loopy=0; while (\$loopy<5) { \$bones=\$kirk[\$loopy]; if (\$bones<>"") {include('display_entry.php');} \$loopy=\$loopy+1; } ?> Troll, go away. Aug 6 '08 #2

 P: n/a On Wed, 6 Aug 2008 19:08:40 +0100, Krustov What is wrong with this php code ? .(it works fine - but something that just works isnt good enough for thisnewsgroup is it) 55) {break;}if (\$loopy>222) {\$kon="break";}\$loopy=\$loopy+1;}sort(\$kirk); \$kirk=array_keys(array_flip(\$kirk));\$loopy=0;while (\$loopy<5){\$bones=\$kirk[\$loopy];if (\$bones<>"") {include('display_entry.php');}\$loopy=\$loopy+1;}?> Krusty, one day soon your code will be used by all the great teaching establishments of the world. Here is example code to take the breath away. Clarity, beauty, functionality, conciseness - out the window with you! Here are perfect examples of how not to write code. Never in the field of computer programming has so much crap been written by so few. P.S. if you wrote your code properly you would see the problem on the 6th line after

 P: n/a Message-ID: What is wrong with this php code ? .(it works fine - but something that just works isnt good enough for thisnewsgroup is it) Why don't you just tell us what it's supposed to do? If you just need five random numbers from a range you've got waaay too much code. -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 6 '08 #4

 P: n/a What is wrong with this php code ? . (it works fine - but something that just works isnt good enough for this newsgroup is it) Why don't you just tell us what it's supposed to do? If you just need five random numbers from a range you've got waaay too much code. www.jpgimage.co.uk/full.php?image=1232 www.jpgimage.co.uk/full.php?image=1233 I needed something to fill up the guestbook.php page and displaying some random guestbook entrys was the quick fix solution i came up with . As the (latest entrys) button is right next to it - obviously its best to display the oldest of the 5 random entrys first . Can you post 1 or 2 lines of 'magic wand' code to do the same job ? . Aug 6 '08 #5

 P: n/a On Aug 7, 12:18*am, Krustov >What is wrong with this php code ? . >(it works fine - but something that just works isnt good enough for this >newsgroup is it) Why don't you just tell us what it's supposed to do? *If you just need five random numbers from a range you've got waaay too much code. http://www.jpgimage.co.uk/full.php?i...php?image=1233 I needed something to fill up the guestbook.php page and displaying some random guestbook entrys was the quick fix solution i came up with . As the (latest entrys) button is right next to it - obviously its best to display the oldest of the 5 random entrys first . Can you post 1 or 2 lines of 'magic wand' code to do the same job ? . if you have \$n entries, how about doing something like Granted, it isn't fast, but it's easy to read/maintain and the speed difference will be negligible if \$n isn't very high. Sorry about my earlier post, I thought you were making a joke. -egbert Aug 6 '08 #6

 P: n/a <0a**********************************@34g2000hsh.g ooglegroups.com> if you have \$n entries, how about doing something like Granted, it isn't fast, but it's easy to read/maintain and the speed difference will be negligible if \$n isn't very high. What about the code used to display the 5 random entrys . Aug 6 '08 #7

 P: n/a Message-ID: Can you post 1 or 2 lines of 'magic wand' code to do the same job ? . Yep. Let's say you have entries numbered from 0 to \$n \$rand_entries = array_rand(range(0, \$n), 5); //\$rand_entries is now an array containing 5 random numbers between 0 and \$n -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 6 '08 #8

 P: n/a Message-ID: Let's say you have entries numbered from 0 to \$n\$rand_entries = array_rand(range(0, \$n), 5);//\$rand_entries is now an array containing 5 random numbers between 0and \$n Hey look - a UK lottery ball picker! asort(\$ar=array_rand(range(1, 49), 6)); echo implode(", ", \$ar); -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 6 '08 #9

 P: n/a Can you post 1 or 2 lines of 'magic wand' code to do the same job ? . Yep. Let's say you have entries numbered from 0 to \$n \$rand_entries = array_rand(range(0, \$n), 5); //\$rand_entries is now an array containing 5 random numbers between 0 and \$n You left out how to sort them into the lowest number first - and you left out how to display the 5 entrys . That must be where the magic wand comes in eh! :-) Aug 6 '08 #10

 P: n/a Message-ID: You left out how to sort them into the lowest number first - See other post >and youleft out how to display the 5 entrys . As I've no idea how you are storing your entries that's not really possible is it? I'd be storing them in a database in which case I'd simply pass the values into a query. -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 6 '08 #11

 P: n/a Message-ID: That must be where the magic wand comes in eh! :-) Looking at it again, if \$bones is the variable to get the entry \$rand_entries = array_rand(range(0, \$n), 5); foreach(\$rand_entries as \$bones){ include('display_entry.php'); } -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 6 '08 #12

 P: n/a ..oO(Krustov) > >Can you post 1 or 2 lines of 'magic wand' code to do the same job ? . Yep.Let's say you have entries numbered from 0 to \$n\$rand_entries = array_rand(range(0, \$n), 5);//\$rand_entries is now an array containing 5 random numbers between 0and \$n You left out how to sort them into the lowest number first - and youleft out how to display the 5 entrys .That must be where the magic wand comes in eh! :-) What about \$ds9['sisko']? You have your entries stored somewhere, either in a \$ds9['dax'] or in a \$ds9['odo'] so that they can be \$ds9['beamed']. Each entry should have its own \$ds9['rank']. Then just take the \$ds9['defiant'], pick \$ds9['quark'] out of the \$ds9['bar'] and load those \$ds9['founders'] from wherever they're stored. \$ds9['garak'] might also offer some helpful tricks. Micha PS: \$ds9 = array_map('str_rot13', array( 'sisko' ='EGSZ', 'dax' ='QO', 'odo' ='syng svyr', 'quark' ='svir enaqbz ahzoref', 'garak' ='Neenl fbegvat shapgvbaf', 'founders' ='negvpyrf', 'defiant' ='uvturfg ahzore', 'bar' ='enatr', 'rank' ='havdhr ahzrevp VQ', 'beamed' ='ernq vagb na neenl' )); Aug 7 '08 #13

 P: n/a Message-ID: <84********************************@4ax.comfrom Michael Fesser contained the following: >What about \$ds9['sisko']? The last time I said that I was told "Mark this well, you won't see a more pedantic, asinine response to aquestion again." Message id 31**********************************...oglegroups.com >You have your entries stored somewhere, eitherin a \$ds9['dax'] or in a \$ds9['odo'] so that they can be \$ds9['beamed']. It's \$ds9['odo'] or more likely multiple \$ds9['odo'] Krusty doesn't do \$ds9['dax'] >Each entry should have its own \$ds9['rank']. I'm guessing there will be a separate \$ds9['odo'] for each entry. -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 7 '08 #14

 P: n/a Krustov wrote: What is wrong with this php code ? . (it works fine - but something that just works isnt good enough for this newsgroup is it) Why don't you try making your code readable? > while (\$kon=="repo") { \$khan=(rand()%\$chekov); \$khan=\$khan+1; \$some_integer++ is available and widely used. Where is \$checkov? if (\$kirk[\$khan]=="") {\$spock=\$spock+1; \$kirk[\$spock]=\$khan;} if (\$spock>55) {break;} if (\$loopy>222) {\$kon="break";} \$loopy=\$loopy+1; } None of that makes any sense to me. Why all these specific values for variables? > sort(\$kirk); \$kirk=array_keys(array_flip(\$kirk)); \$loopy=0; while (\$loopy<5) { \$bones=\$kirk[\$loopy]; if (\$bones<>"") {include('display_entry.php');} \$loopy=\$loopy+1; } None of this makes any sense. Nobody has a magick wand, what we all try to do is make logical code that is readable and maintainable. Try looking at your code a year later and see if it makes any sense, and you wrote it. Imagine what it looks like to us? I'm not sure what you are doing but it looks like you are pulling 5 random entries from some file and sorting by date. A database is ideally suited for this type of work and the select to do this is simple. This has all the appearance of something you just kept fudging with until you got what you thought you wanted. Jeff > ?> Aug 7 '08 #15

 P: n/a None of that makes any sense to me. Does that mean your not as smart or as clever as you like to think you are or pretend to be . Aug 7 '08 #16

 P: n/a That must be where the magic wand comes in eh! :-) Looking at it again, if \$bones is the variable to get the entry Not everybody uses agent . Could you do everybody a favour and insert a blank line between the quote and the reply - or dont you care . Aug 7 '08 #17

 P: n/a What is wrong with this php code ? . The new improved code . "") {include('display_entry.php');} \$loopy=\$loopy+1; } ?> Aug 7 '08 #18

 P: n/a Krustov wrote: >None of that makes any sense to me. Does that mean your not as smart or as clever as you like to think you are or pretend to be . It means you code is unclear and obtuse. You may think it's cute to use such variable names, but it isn't. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. js*******@attglobal.net ================== Aug 7 '08 #19

 P: n/a Message-ID: Could you do everybody a favour and insert a blank line between thequote and the reply - or dont you care . ROFL!!! -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 7 '08 #20

 P: n/a Jerry Stuckle wrote: Krustov wrote: > >>None of that makes any sense to me. Does that mean your not as smart or as clever as you like to think youare or pretend to be . It means you code is unclear and obtuse. You may think it's cute to use such variable names, but it isn't. That's exactly what it means. Now, I have never claimed to be particularly clever or smart. I am a PHP newbie and I have stated that where appropriate (read my posting history). I am here to learn and to give a little advice where I believe my advice would be useful. Just because I'm a php newbie though doesn't mean I'm new at either usenet or programming. And I can clearly tell that you are heading for trouble by picking unneeded and unwanted fights with people that really don't (yet) have a bone to pick with you. So, I'm going to have one more run at this. Don't alienate the people that can be of assistance to you. Don't make yourself the group pariah. Now, if you just can't grok that, then you will be in my rather lonely kill file. And you'll be in others as well. Jeff > Aug 7 '08 #21

 P: n/a (read my posting history) Your own self importance is of no interest to me . Aug 7 '08 #22

 P: n/a Krustov wrote: >(read my posting history) Your own self importance is of no interest to me . *plonk* Only one in my in killfile. You are absolutely clueless. Jeff Aug 7 '08 #23

 P: n/a Krustov schreef: >(read my posting history) Your own self importance is of no interest to me . Dear Krustov, Are you posting in here to get help or to irritate people? Jeff's first response could have been useful to you, if you read it right (and understand of course). Erwin -- ============================ Erwin Moller Now dropping all postings from googlegroups. Why? http://improve-usenet.org/ ============================ Aug 7 '08 #24

 P: n/a <48***********************@news.xs4all.nl> (read my posting history) Your own self importance is of no interest to me . Dear Krustov, Are you posting in here to get help or to irritate people? I'm a troll who also has a interest in php scripting - so both . Aug 7 '08 #25

 P: n/a Message-ID: Are you posting in here to get help or to irritate people? I'm a troll who also has a interest in php scripting - so both . Krusty is a fascinating person. These days you have to give a few points for accessing and participating in Usenet by means other than Google groups. He calls himself a troll but really he's far too voluble to be a troll in the classic sense. But there is no question that he gets a kick from winding people up. At the same time he has perceived a need to learn some scripting. Now trying to get help from people whilst simultaneously pissing them off must place him in a continual dilemma. A few more points added to his score. But it's not only people he rebels at, if the textbooks say name variables sensibly, he will name them \$poo or \$jobby. He has a very limited PHP toolkit and so his solutions tend to be a bit convoluted. But he does get stuff written and done and it does work, after a fashion, so he gets a few more points for that. If you try to help him don't expect gratitude, he's more likely to call you a c*nt.. If he posts something that interests me, I'll respond, not to help him, but because it amuses /me/ and may be helpful to others. It is, after all, only Usenet. -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 7 '08 #26

 P: n/a Geoff Berrow wrote: Message-ID: >Are you posting in here to get help or to irritate people? I'm a troll who also has a interest in php scripting - so both . Krusty is a fascinating person. These days you have to give a few points for accessing and participating in Usenet by means other than Google groups. He calls himself a troll but really he's far too voluble to be a troll in the classic sense. But there is no question that he gets a kick from winding people up. At the same time he has perceived a need to learn some scripting. Now trying to get help from people whilst simultaneously pissing them off must place him in a continual dilemma. A few more points added to his score. But it's not only people he rebels at, if the textbooks say name variables sensibly, he will name them \$poo or \$jobby. He has a very limited PHP toolkit and so his solutions tend to be a bit convoluted. That's a bit of an issue when he offers "help". Though there may be something useful in there, its outweighed by the accompanying crud. Certainly not a coding style anyone should be learning from. From what I see, most people recognize this quickly. So Krusty is largely a waste of time, unique in his own way, but hardly useful. Jeff. But he does get stuff written and done and it does work, after a fashion, so he gets a few more points for that. If you try to help him don't expect gratitude, he's more likely to call you a c*nt.. If he posts something that interests me, I'll respond, not to help him, but because it amuses /me/ and may be helpful to others. It is, after all, only Usenet. Aug 7 '08 #27

 P: n/a That's a bit of an issue when he offers "help". Though there may be something useful in there, its outweighed by the accompanying crud. Certainly not a coding style anyone should be learning from. You place quite a high value on your own opinions . Lex Luthor once said that some people can read 'war and peace' and come away thinking its nothing more than a simple fairytale - while others can read the contents of a box of matches and unravel the mysterys of the universe . Aug 7 '08 #28

 P: n/a Message-ID: That's a bit of an issue when he offers "help". Though there may besomething useful in there, its outweighed by the accompanying crud.Certainly not a coding style anyone should be learning from. He posts crud and five people (who may not have responded) immediately post better versions. Could be seen as a positive, perhaps? -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 7 '08 #29

 P: n/a <56********************************@4ax.com> That's a bit of an issue when he offers "help". Though there may be something useful in there, its outweighed by the accompanying crud. Certainly not a coding style anyone should be learning from. He posts crud and five people (who may not have responded) immediately post better versions. Could be seen as a positive, perhaps? Quite the little analyst - arnt you . To sum things up , If you just ask a general question on usenet then most people will just click on the next unread post . But if given the oppertunity to correct somebody else - then a overwhelming urge to reply appears as most sad bastards on usenet dont have a girlfriend and wanky little ego trips are one of their few pleasures in what they regard as being normal everyday life . As spock would say ..... its all very logical :-) Aug 7 '08 #30

 P: n/a Geoff Berrow wrote: Message-ID: That's a bit of an issue when he offers "help". Though there may besomething useful in there, its outweighed by the accompanying crud.Certainly not a coding style anyone should be learning from. He posts crud and five people (who may not have responded) immediately post better versions. Could be seen as a positive, perhaps? OK. It's not often that a newbie gets to see see how a convoluted mess can be boiled down to clear code with a little thought. I think it's a good idea to give newbies a desire to not only solve their problems but see the benefit of learning to be a better coder. Jeff > Aug 7 '08 #31

 P: n/a It's not often that a newbie gets to see see how a convoluted mess can be boiled down to clear code with a little thought. I think it's a good idea to give newbies a desire to not only solve their problems but see the benefit of learning to be a better coder. Do you ever post any php code snippets on here . Or perhaps you regard comp.lang.php as being nothing more than a soapbox for your own personal thoughts and opinions . Aug 7 '08 #32

 P: n/a Message-ID: He posts crud and five people (who may not have responded) immediatelypost better versions.Could be seen as a positive, perhaps? OK. It's not often that a newbie gets to see see how a convoluted messcan be boiled down to clear code with a little thought. I think it's agood idea to give newbies a desire to not only solve their problems butsee the benefit of learning to be a better coder. Indeed. Krusty serves as a bad example to us all. :-)) -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 http://slipperyhill.co.uk Aug 7 '08 #33

 P: n/a ..oO(Geoff Berrow) >Message-ID: >He posts crud and five people (who may not have responded) immediatelypost better versions.Could be seen as a positive, perhaps? OK. It's not often that a newbie gets to see see how a convoluted messcan be boiled down to clear code with a little thought. I think it's agood idea to give newbies a desire to not only solve their problems butsee the benefit of learning to be a better coder. Indeed. Krusty serves as a bad example to us all. :-)) He's an example of how things should _not_ be done. If just someone would have told this to his mother before it was too late ... ;-D Micha Aug 7 '08 #34