Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I was thinking something like this $prob = number_format(mt_rand(1,100)/100, 2) ; $q = $db->query("SELECT * FROM rpg_monsters WHERE monster_zone = 1 AND chance >= $prob ORDER BY chance LIMIT 1"); $monsterdata = $db->fetch_assoc($q); So, in theory, if prob > 10 you get no monsters, 10% of the time you get a white one and 4% you get a unique one
  2. Sorry, I don't understand what you are trying to do.
  3. @Frank_b Custom sort functions are required to return -ve, 0, +ve depending an whether $a is lower, equal or higher than $b. You are returning boolean values. So to sort on (Points DESC, Id ASC) it would be function advancedSort($a, $b) { $tmp = $b['Skill_Points'] - $a['Skill_Points']; if ($tmp==0) { // points are the same return $a['Skill_Id'] - $b['Skill_Id']; } else return $tmp; } $arr = array( array ('Skill_Id' => 2, 'Skill_Points' => 5), array ('Skill_Id' => 3, 'Skill_Points' => 2), array ('Skill_Id' => 5, 'Skill_Points' => 5), array ('Skill_Id' => 4, 'Skill_Points' => 1), array ('Skill_Id' => 1, 'Skill_Points' => 3), ); usort($arr, 'advancedSort'); echo '<pre>',print_r($arr, true),'</pre>'; Resulting in Array ( [0] => Array ( [Skill_Id] => 2 [Skill_Points] => 5 ) [1] => Array ( [Skill_Id] => 5 [Skill_Points] => 5 ) [2] => Array ( [Skill_Id] => 1 [Skill_Points] => 3 ) [3] => Array ( [Skill_Id] => 3 [Skill_Points] => 2 ) [4] => Array ( [Skill_Id] => 4 [Skill_Points] => 1 ) ) However, when you sort() a two dimensional array it will sort on the values of the first elements. So if you just want a sort on Skill_id sort($arr); giving Array ( [0] => Array ( [Skill_Id] => 1 [Skill_Points] => 3 ) [1] => Array ( [Skill_Id] => 2 [Skill_Points] => 5 ) [2] => Array ( [Skill_Id] => 3 [Skill_Points] => 2 ) [3] => Array ( [Skill_Id] => 4 [Skill_Points] => 1 ) [4] => Array ( [Skill_Id] => 5 [Skill_Points] => 5 ) )
  4. Try something like function getFilterVal($fname) { $p1 = strpos($fname,'('); $p2 = strrpos($fname,')'); return substr($fname, $p1+1, $p2-$p1-1); } $dir = array ( 'file_A(Edinburgh).jpg', 'file_B(Edinburgh).jpg', 'file_C(Glasgow).jpg', 'file_D(Edinburgh).jpg' ); // PROCESS THE FILES AND STORE IN 2D ARRAY BY FILTER VALUE $files = array(); foreach ($dir as $fname) { $filter = getFilterVal($fname); $files[$filter][] = $fname; } which gives $files Array ( [Edinburgh] => Array ( [0] => file_A(Edinburgh).jpg [1] => file_B(Edinburgh).jpg [2] => file_D(Edinburgh).jpg ) [Glasgow] => Array ( [0] => file_C(Glasgow).jpg ) ) then $dropdownVals = array_keys($files); Now you have $dropdownVals Array ( [0] => Edinburgh [1] => Glasgow )
  5. It seems to me that Relational Algebra is much the the same as 4th Normal Form and higher - fine for the classroom but something never used in practice.
  6. Add unique key on Osiris(Name, Expansion, Foil); Then, when you insert use INSERT INTO Osiris( <fields> ) VALUE ( <vals> ) ON DUPLICATE KEY UPDATE stock = stock + $qty Now when inserting and the same combination already exists then the stock will be updated instead of creating a new record
  7. Can't you just work with a simple 1-D array where $skillTree[$skill_id] = $skill_points; then the test would be if (array_keys($skillTree) == range(1,9)
  8. @QuickOldCar Why are you concatenating in that double-quoted example? What if the username is O'Brien?
  9. Just create a simple single dimension array then use array_unique. You are creating an array containing several one-item arrays $arr = array ('Glasgow', 'Edinburgh', 'Edinburgh', 'Edinburgh'); $uniq = array_unique($arr);
  10. Are you looking for something like this? SELECT SUM(IF(Name='$name'),1,0) as namecheck , SUM(IF(Expansion='$expansion'),1,0) as expcheck , SUM(IF(Foil='$foil'),1,0) as foilcheck FROM Osiris WHERE (Name='$name') OR (Expansion='$expansion') OR (Foil='$foil') Or are you looking for those where all 3 match the criteria. It's impossible to tell what you want from your post and current query
  11. The correct way to do it is to normalize your data and remove the groups g1, g2,..., gN from the services table and to create a new table, say, service_group. The group ids should each be stored in a separate row with the service_id +-------------------+ +-------------+ | add_service | | ugroup | +-------------------+ +-------------+ | id | ---+ +------ | id | | title | | +-----------------+ | | ugroup | | description | | | service_group | | +-------------+ +-------------------+ | +-----------------+ | +----< | service_id | | | ugroup_id | >---+ +-----------------+ Then for each checkbox that was checked you write a record to this third table
  12. Again, as there is a LEFT JOIN to t2 that condition should be in the t2 JOIN ON clause and not the WHERE clause
  13. Or SELECT id , TIMEDIFF(CURTIME(), time) as diff FROM test_table
  14. I notice you are grouping by a value that may not exist too. Try GROUP BY t1.id
  15. If that condition is require it needs to be part of the JOIN condition (as it is a left join on t5) and removed from the WHERE clause ... LEFT JOIN `archive_expiration` AS `t5` ON `t1`.`id` = `t5`.`propid` AND `t5`.`userid` = '599zxj' ...
  16. OK, plan B $names = array ('anna','bert','ben','cait','alan','andrew','bob','carry', '23 kenny','10','43 lala'); sort($names); foreach ($names as $n) { $x = "$n"; // cast the name as a string if (is_numeric($x[0])) $newArray['#'][] = $n; else $newArray[$x[0]][] = $n; } Gives Array ( [#] => Array ( [0] => 10 [1] => 23 kenny [2] => 43 lala ) [a] => Array ( [0] => alan [1] => andrew [2] => anna ) [b] => Array ( [0] => ben [1] => bert [2] => bob ) [c] => Array ( [0] => cait [1] => carry ) )
  17. do you mean $nums = array (1234,28975,9258,44,950,40582,21,456); sort($nums); foreach ($nums as $n) { $x = "$n"; // cast the number as a string $newArray[$x[0]][] = $n; } Gives Array ( [2] => Array ( [0] => 21 [1] => 28975 ) [4] => Array ( [0] => 44 [1] => 456 [2] => 40582 ) [9] => Array ( [0] => 950 [1] => 9258 ) [1] => Array ( [0] => 1234 ) )
  18. The mod operator "%" gives the remainder when a number is divided by another. So if you keep a count of the rows ($rowcount) then start a new table row when $rowcount % 3 == 0
  19. You have already posted this question. Don't double post. http://forums.phpfreaks.com/topic/291491-query-help-grouping/?do=findComment&comment=1492979
  20. try $names = array ('anna','bert','ben','cait','alan','andrew','bob','carry'); sort($names); foreach ($names as $n) { $newArray[$n[0]][] = $n; }
  21. Define the function as function className($nametoUse, $extra='' ){ ... } Then the extra parameter is optional, and empty if you do not provide it.
  22. Like this <?php $is = ''; $msg = ''; while($row = mysqli_fetch_array($q) ){ if($is != $row['is_id']){ if ($is != '') { // send $msg to $is email } $msg = ''; $is = $row['is_id']; } $msg .= $row['client_name'] . ' --- ' . $row['full_name'] . ' LINK <br/>'; } // send final $msg to $is email ?>
  23. You will also need to call the same output function after the loop to process the final email
  24. for ($q=1; $q<=$quantity; $q++) { // output option $q }
  25. Sorry to disappoint you but nothing better springs to mind
×
×
  • 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.