Jump to content

byroncoolie

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

About byroncoolie

  • Birthday 08/28/1970

Contact Methods

  • Website URL
    http://www.dinosaurus.com.au/f1/f1.html

Profile Information

  • Gender
    Not Telling
  • Location
    Melbourne, Australia

byroncoolie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Friends, I have a PHP script that populates a calendar based on an array as follows: $days = array(2=>array('javascript:showWhatsOnText(2);','linked-day'), 3=>array('javascript:showWhatsOnText(3);','linked-day'), 4=>array('javascript:showWhatsOnText(4);','linked-day')); echo generate_calendar(2011, 4, $days, 1, '#'); where, for instance, the 2, 3 4 are the days of the month, By extracting a series values from a MySQL database how would I generate this array dynamically. E.g I have startday, startmonth, name and text fields in the database and would need to loop through them all to create the array. I tried playing around with something like this without any luck: $queryCat1 = "SELECT * FROM $dbCalendarEvents ORDER BY id ASC"; // WHERE visible = '1' $result1 = mysql_query($queryCat1) or die (mysql_error()); $num1 = mysql_num_rows($result1); $i=0; $daysArray = array(); while ($i < $num1) { $startday=mysql_result($result1,$i,"startday"); $startmonth=mysql_result($result1,$i,"startmonth"); $name=mysql_result($result1,$i,"name"); $name=mysql_result($result1,$i,"name"); $copy=mysql_result($result1,$i,"copy"); $daysArray[$i] = $startday=>array('/weblog/archive/2004/Jan/02','linked-day'); $i++; } Your help is appreciated.
  2. Thank you, I did consider the length of the URL but the (obscure) error message swayed me from this. I investigated it further by changing the GET to a POST and have resolved the issue. Thanks. Here's the final code: THE SORT PAGE: <script type="text/javascript"> $(document).ready(function() { $("#list").sortable({ // list is the id of the UL handle : '.handle', update : function () { var order = $('#list').sortable('serialize'); // produces string of listItem[]=1&listItem[]=3&listItem[]=2 where listItem is the id of the LI's in the UL $.post('product_sortable-process.php', order); } }); }); </script> THE ACTION PAGE: foreach ($_POST['listItem'] as $position => $item){ $sql = "UPDATE $dbProd SET `position` = '$position' WHERE `id` = '$item'"; mysql_query($sql) or die(mysql_error()); } All thanks to this post by Bart: http://stackoverflow.com/questions/654535/jquery-what-to-do-with-the-list-that-sortableserialize-returns
  3. It's part of a CMS. The page that displays all products has the facility to re-order them by dragging and dropping, hence the basic ajax functionality. By dragging and dropping this creates a querystring of all the new order ids and product ids which is then processed by a script to do the database work. The querystring looks like this: ?listItem[]=1&listItem[]=3&listItem[]=2 etc etc. When this exceeds 280 items it fails in the script that splits the array and does the database update. The database cannot handle more than 280 requests in the loop. Here is the actual script (we have used this in our build): http://www.wil-linssen.com/musings/entry/extending-the-jquery-sortable-with-ajax-mysql/ Hope this helps.
  4. Thanks in advance all. I have an AJAX list sorting script that loops through an array and changes the 'position' field in a db table. This works great until the number of records in the array exceeds 280. I'm trying to work out how to overcome this. A time delay usleep() does not help. Perhaps I need to count the records and split the operation of the function into blocks of 280. Perhaps I need to open a database connection then close it and open it again after 280 records. Here is the script: foreach ($_GET['listItem'] as $position => $item){ $sql = "UPDATE $dbProd SET `position` = '$position' WHERE `id` = '$item'"; mysql_query($sql) or die(mysql_error()); $query .= $sql; } print_r ($query);
  5. To whom it concerns, I have a formula one racing calculator that should work like this: 1. Through the GUI users guess the top 8 drivers in the order they think they will finish. 2. Through the GUI users guess who will get the fastest lap. 3. Through the GUI users guess who will start at pole position. (these are written to the MySQL database in a 'racebets' table) 4. When a race is run, the administrator enters the actual top drivers in order and who got the fastest lap and pole position. (these are written to the MySQL database in a 'raceresults' table) 5. A php calculation is done against the two database tables whereby, if a user guessed a driver in the correct position in the top eight, the points array distributes points as follows (10,8,6,5,4,3,2,1). Just by guessing a driver in the top 8 (whether in the correct position or not) the user gets 1 point i.e. if you guess Michael Schumacher to come first and he does come first, you get 11 points (10 + 1). If you guess Michael Scumacher to come first and he actually comes third, you get 1 point etc etc... If the user guessed the driver with the fastest lap they get 3 points and pole position they get 3 points too. Here is the script that is being used but IT IS NOT CALCULATING CORRECTLY and so we are forced to calculate manually and enter the results in the database manually! --------------------- class pointCalculator { //amount of points earned var $earnedPoints; //points given for each guess var $pointHash; //drivers that user has selected var $selectedDrivers; //real drivers in the end of the race var $finalDrivers; //pole driver var $poleDriver; //driver with fastest lap var $fastestDriver; /** * @return void * @param * @desc Constructor */ function pointCalculator(){ $this->earnedPoints=0; $this->setPoints(array(10,8,6,5,4,3,2,1)); } /** * @return void * @param int $n * @desc Set the pole driver */ function setPole($n){ /* if(!is_numeric($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } */ $this->poleDriver=$n; } /** * @return void * @param int $n * @desc Set the faster driver. */ function setFastest($n){ /* if(!is_numeric($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } */ $this->fastestDriver=$n; } /** * @return void * @param array $n * @desc Set drivers selected by user */ function setSelected($n){ if(!is_array($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } $this->selectedDrivers=$n; } /** * @return void * @param array $n * @desc Set drivers selected by user */ function setSelectedFastest($n){ /* if(!is_numeric($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } */ $this->selectedFastest=$n; } /** * @return void * @param array $n * @desc Set drivers selected by user */ function setSelectedPole($n){ /* if(!is_numeric($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } */ $this->selectedPole=$n; } /** * @return void * @param hash $n * @desc Set amount of points per dirver (IN ORDER) */ function setPoints($n){ /* if(!is_numeric($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } */ $this->pointHash=$n; } /** * @return void * @param int $n * @desc Set results of race */ function setFinalDrivers($n){ if(!is_array($n)){ echo 'Wrong usage in'.__FILE__.':'.__LINE__; return; } $this->finalDrivers=$n; } /** * @return int * @param * @desc Get calculated score */ function calculate(){ foreach($this->finalDrivers as $k=>$v){ if($this->selectedDrivers[$k]==$v) $this->earnedPoints+=$this->pointHash[$k]; if(in_array($v,$this->selectedDrivers)) $this->earnedPoints++; } // check pole and fastest if($this->selectedPole==$this->poleDriver) $this->earnedPoints+=3; if($this->selectedFastest==$this->fastestDriver) $this->earnedPoints+=3; return $this->earnedPoints; } } --------------------- If you can help that would be fantastic... P.S. You can view the f1 tipping comp at: http://www.f1tipping.org/ Regards, Byron
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.