RE: [PHP-DB] Rand() Emulation
ORDER BY RAND() is not very performance wise. Try to do the rand outside of the DB and get your random record with that number. Sincerely berber Visit http://www.weberdev.com/ Today!!! To see where PHP might take you tomorrow. -Original Message- From: Gerard Samuel [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 24, 2003 6:19 PM To: Doug Thompson Cc: Becoming Digital; PHP-DB Subject: Re: [PHP-DB] Rand() Emulation Im probably not making myself clear. Ultimately, my goal is to emulate mysql's - SELECT * FROM TABLE ORDER BY RAND() LIMIT (X) for other databases that do not support RAND(). So using variations of php's rand(), wouldn't make sense, as it only picks one value out of a range of values, that are numerical in nature. But here is an idea, that Im thinking about, but haven't gotten to the code as yet. 1. In the tables that I want random values from, create a rand column, that contains incremental numerical values for each row. 2. select the the maximum number from the rand column. 3. Assume that there are no gaps between 0 and this max number. 4. Create an array of numbers with values between 0 and max number. 5. Use array_rand() to randomly choose (x) values from the array created in step 4. (I may choose maybe a 1 or 2 values more than whats required, just in case of gaps between 0 and max number in step 3). 6. Use these randomly choosen values to select from the database as random rows. So hopefully its a bit clearer what Im striving for. To me the idea above would work, but it hinges on if that rand column, doesn't have gaps. If you see room for improvement, or have another idea, or if Im talking gibberish then by all means. Thanks. Doug Thompson wrote: An incredible interpretation of quote If called without the optional min, max arguments rand() returns a pseudo-random value between 0 and RAND_MAX. If you want a random number between 5 and 15 (inclusive), for example, use rand (5, 15). /quote Doug -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Accessing MySql using Flash while using PHP as the middleware
Does anybody have an idea how-to use Flash and PHP to access a MySql database. I know how to use PHP and mysql with no problem to pull info, but with Flash I am struggling. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Accessing MySql using Flash while using PHP as themiddleware
Might want to check out a article on devshed: http://devshed.com/Client_Side/Flash/DataDrivenFlash/page1.html On Wed, 2003-06-25 at 11:15, Ron Allen wrote: Does anybody have an idea how-to use Flash and PHP to access a MySql database. I know how to use PHP and mysql with no problem to pull info, but with Flash I am struggling. -- Adam Voigt ([EMAIL PROTECTED]) Linux/Unix Network Administrator The Cryptocomm Group -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Accessing MySql using Flash while using PHP as themiddleware
on 25/6/03 4:15 pm, Ron Allen at [EMAIL PROTECTED] wrote: Does anybody have an idea how-to use Flash and PHP to access a MySql database. I know how to use PHP and mysql with no problem to pull info, but with Flash I am struggling. Look on flashkit.com -- Mike Karthauser Managing Director - Brightstorm Ltd Email[EMAIL PROTECTED] Web http://www.brightstorm.co.uk Tel 0117 9426653 (office) 07939 252144 (mobile) SnailmailUnit 8, 14 King Square, Bristol BS2 8JJ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Accessing MySql using Flash while using PHP as the middleware
Adam made a good suggestion - but using LoadVars is better, and if you are retrieving text it's easier to bring it back as an xml file, otherwise an ampersand stops you cold. Here's my call to the login script to authenticate users for a news site when the login button is clicked. The varSender and varReceiver are recommended by Colin Moock to avoid caching. His ActionScript for Flash MX The Definitive Guide, O'Reilly, ISBN 0-596-00396-X is worth every penny. Also visit www.moock.org Values in first_txt.text, last_txt.text, and pass_txt.text come from those text boxes. The variable host is retrieved from a settings.as file in the first frame of the movie. ckval is stored in a shared object so that subsequent logins are automatic. autologin = true is the key which unlocks the rest of the movie read is the frame where another script loads the day's news stories, also stored in a MySQL database. frame 7 is for login failed - when I added it I had no space to name it. So, what does the php script return? Exactly this, with no leading space or empty line, and on one line: ValidLogin=trueckval=some32bitkeyiwonttypeout (I was tearing my hair out - everything looked RIGHT, yet the movie kept failing, dumbly. Then I realized there was a blank like ahead of the returned values. Removed it and magic happened.) Flash is alternately exasperating and wonderful. HTH - Miles --- flash code calling PHP script function onLogin(){ if(first_txt.length 0 last_txt.length 0 pass_txt.length 0) { varSender = new LoadVars(); varReceiver = new LoadVars(); varSender.first_name = first_txt.text; varSender.last_name = last_txt.text; varSender.password = pass_txt.text; varSender.action = 'login'; varSender.sendAndLoad(http://+ host + user_logon.php, varReceiver, 'GET'); varReceiver.onLoad = function() { if(!this.error this.CkVal != ){ subs_so.data.ckVal = this.CkVal; } if(!this.error this.ValidLogin == true) { _root.ValidLogin = this.ValidLogin; _root.gotoAndStop('read'); } else { _root.gotoAndStop(7); } first_txt.selectable = true; last_txt.selectable = true; pass_txt.selectable = true; loginButton.enabled = true; } } } //end of function onLogin end of Flash code --- At 05:15 PM 6/25/2003 +0200, Ron Allen wrote: Does anybody have an idea how-to use Flash and PHP to access a MySql database. I know how to use PHP and mysql with no problem to pull info, but with Flash I am struggling. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Accessing MySql using Flash while using PHP as themiddleware
Fairly simple if you're using Flash MX. In the flash movie create a LoadVars object. myObject = new LoadVars (); create an onLoad event for it... myObject.onLoad = function () { trace (myObject.returnedValue); } drag and drop a button component and name it myButton and add this code. myButton.onRelease = function () { _root.myObject.sentValue = Ron' _root.myObject.sendAndLoad(myPHPpage.php,myObject,post); } now create a php page called myPHPpage.php and include the following... ?php $selectedName=$HTTP_POST_VARS['sentValue'];? ?php echo returnedValue=.$selectedName. Allen; ? Don't put ANYTHING else in this PHP page. No space, no html markup, nothing. That should do it. I haven't tested the code, it just sort of flew out of my fingers but it should would. Doing a google search on Flash and PHP turns up tons of rescources. Good luck! Tim Winters Creative Development Manager Sampling Technologies Incorporated 1600 Bedford Highway, Suite 212 Bedford, Nova Scotia B4A 1E8 www.samplingtechnologies.com [EMAIL PROTECTED] [EMAIL PROTECTED] Office: 902 450 5500 Cell: 902 430 8498 Fax:: 902 484 7115 -Original Message- From: Ron Allen [mailto:[EMAIL PROTECTED] Sent: June 25, 2003 12:15 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Accessing MySql using Flash while using PHP as the middleware Does anybody have an idea how-to use Flash and PHP to access a MySql database. I know how to use PHP and mysql with no problem to pull info, but with Flash I am struggling. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php