Jump to content

Scooby08

Members
  • Posts

    244
  • Joined

  • Last visited

Everything posted by Scooby08

  1. Ok I figured out why mine wasn't working. Some of the keys begin with a capital letter. I need to sort something more like this and I do not want to change the case of the keys either.. <?php $array = array('One' => array(), 'two' => array(), '_three' => array()); ksort($array); echo "<pre>".print_r($array, true)."</pre>"; ?> Output Array ( [One] => Array ( ) [_three] => Array ( ) [two] => Array ( ) )
  2. Tried that.. If it were only that easy.. It sorts with underscores last.. I'm thinking it might have to have some sort of usort function written for it.. The following used to work, but my array has changed and now it needs to be modified to work with keys rather than values.. <?php function sortUnderscoreToFront($a, $b) { if (substr($a['category'], 0, 1) == '_' || substr($b['category'], 0, 1) == '_') { return ((substr($a['category'],0,1)=='_')?-1:1); } return strcmp(strval($a['category']), strval($b['category'])); } usort($templates_array, 'sortUnderscoreToFront'); ?>
  3. Say I have this array: <?php $array = array('one' => array(), 'two' => array(), '_three' => array()); ?> How could I sort that array so it ends up like so: Array ( [_three] => Array ( ) [one] => Array ( ) [two] => Array ( ) ) Thanks!!
  4. Thanks a ton.. That helped get me going in the right direction..
  5. Well the deal is I'm just wanting to show the audio div on the home page.. So if var URL = 'http://www.host.com/contact/' the audio should not show..
  6. Ok.. If that's the case then I'm not understanding the issue here then.. The below still does not work in IE.. Works in all other browsers.. var URL = window.location.href; if (URL == 'http://www.host.com/') { $('#audio').show(); } else { $('#audio').hide(); }
  7. This works in all browsers but IE.. Would anybody happen to know of a work around? var URL = window.location.href.toString(); if (URL == 'http://www.host.com/') { $('#audio').show(); } else { $('#audio').hide(); } Thank you..
  8. Hello again mjdamato.. Had to step away for a bit.. But I just got to testing it out and guess what? It's Money! Seems to do exactly what I needed... I'll work this in and see if any other issues arise, but I'm thinking it's all good.. I can't thank you enough.. Thanks a million!
  9. Yeah the table will be rebuilt once I get the loop working.. It was strictly for testing purposes.. And it is an array coming from a database with thousands of records at a time and the unique id is the event id for each group.. So I sorta have to figure it out the way that it is.. I'm really not too sure how I could restructure the array better so it could loop like I want.. Do you have an example? Thank you very much for helping out..
  10. Hey thanks for responding mjdamato.. Yeah I didn't quite know how to explain what I was doing.. Maybe the attached screenshot will help with getting my objective across.. The desired_output.jpg has a couple notes of where the code is going wrong and what it should be doing.. [attachment deleted by admin]
  11. Hello all.. This one's sort of difficult to explain, but yet it should be a pretty simple solution.. What I'm trying to do is loop through an array that has either single event id's or a group of event id's, and run a condition on the change of id's while looping.. Sort of grouping each set if unique id's within a new event section.. Here's sort of a test code I put together: <?php $result = array( array('event_id' => 70), array('event_id' => 70), array('event_id' => 70), array('event_id' => 95), array('event_id' => 96), array('event_id' => 97), array('event_id' => 98), array('event_id' => 99), array('event_id' => 145), array('event_id' => 145), array('event_id' => 145), array('event_id' => 145), array('event_id' => 166), array('event_id' => 166), array('event_id' => 177), array('event_id' => 200), array('event_id' => 200), array('event_id' => 200) ); $previous_id = ''; foreach($result as $row){ if ($row['event_id'] != $previous_id) { echo '<div style="background:#ccc;">New Event</div>'; } if ($previous_id > 0 && $row['event_id'] != $previous_id) { echo '<table border="1"><tr><td>'.$row['event_id'].'</td></tr></table>'; $previous_id = ''; } else { echo $row['event_id'].'<br />'; $previous_id = $row['event_id']; } } ?> It's about half way working, but there are issues when the ids change and they are either single event ids in a row, or multiple same event ids in a row.. I can't think how to set the $previous_id variable properly on each loop.. Well, figured I'd throw it out there and see what happens.. Thanks..
  12. Hello Altrozero.. I just wanted to let you know that your suggestion did work out excellently! Thanks I did notice that you said this query is not exactly very fast.. How many records at a time do you think this query could handle without getting too bogged down? (Ball park) If you, or anybody else reading this, wouldn't mind throwing out some suggestions as to how to speed this up I'd really be interested in that.. Thanks again!
  13. I also found out that LOG is not defined for negative values.. http://forums.mysql.com/read.php?117,219696,264407#msg-264407
  14. Found my answer finally.. Thanks.. CREATE FUNCTION multiply(in_my_id INT) RETURNS DECIMAL(10,2) BEGIN DECLARE total DECIMAL(10,2); SET total = (SELECT EXP(SUM(LOG(COALESCE(multiply,1)))) FROM my_table WHERE my_id = in_my_id); RETURN total; END; http://lists.mysql.com/mysql/166184
  15. Hello.. I'm just wondering if there is a way to multiply a single columns values using a stored function.. Example table: (my_table) id my_id multiply 0 1 2 1 1 2 2 3 2 3 3 2 4 3 2 5 3 2 Now I will never know what the multiply number will be.. I'm using 2 as an example.. Here's pretty close to what I was thinking, but I just don't know how to multiply the fields.. Do I need to run a loop or something like that? CREATE FUNCTION multiply(in_my_id INT) RETURNS DECIMAL(10,2) BEGIN DECLARE total DECIMAL(10,2); SET total = (SELECT multiply FROM my_table WHERE my_id = in_my_id); -- loop here?? RETURN total; END; If in_my_id = 1, then it should return 4.. If in_my_id = 3, then it should return 16.. Thanks for any replies!
  16. Using MySql How in the world would a table like this: id - new_id - result - final_result 0 1 win NULL 1 1 loss NULL 2 2 win NULL 3 2 win NULL be updated into a table like this: id - new_id - result - final_result 0 1 win loss 1 1 loss loss 2 2 win win 3 2 win win Am just trying to check if any group of new_id's has a result value of loss.. if so, update all fields in that group of new_id's to loss, else win.. Thanks!!
  17. Wow did I really over think that one! Yeah that works perfectly obviously.. Thank you for taking my head out of the clouds jesirose!!
  18. Well I did my best to explain.. It's pretty straight forward.. What I was trying to do was update the 'graded_on' field if the value was set to '0000-00-00 00:00:00', which is the default value for that field. Anyways, I did get it working with the following, but I read that it's not too efficient to run an IF statement within the WHERE clause.. Any thoughts? UPDATE table SET graded_on = NOW() WHERE event_status = 'Final' AND IF(graded_on = '0000-00-00 00:00:00', 1, 0) Thanks..
  19. Using MySQL.. Is there a way to make this UPDATE query work either by tweaking what's here or possibly another way? And I don't really want to add another column just to say it's been updated or not.. UPDATE table SET graded_on = IF(graded_on = '0000-00-00 00:00:00', NOW(), '0000-00-00 00:00:00') It seems I cannot use the 'graded_on' field within the graded_on if().. Not sure of another way to get it done.. As is, it updates any graded_on field that does NOT have a value of '0000-00-00 00:00:00'.. Strange that it's doing the opposite of what it should.. Thanks!
  20. I have this function which is javascript and I need to convert it to php.. function US2dec(myUS) { if (myUS.toLowerCase() == 'even') { myUS = '100'; } var myDec; myUS = parseFloat(myUS); if (Math.abs(myUS) < 100 || isNaN(myUS)) { myDec = NaN; } else if (myUS > 0) { myDec = 1 + myUS / 100; } else { myDec = 1 - 100 / myUS; } return myDec.toFixed(; } I came up with this php version and it seems to work but I'm no expert with math functions.. I was hoping somebody who's a bit more familiar with these functions could check it over quick.. function US2dec($myUS) { if (strtolower($myUS) == 'even') { $myUS = 100; } $myDec = 0; $myUS = floatval($myUS); if (abs($myUS) < 100 || !is_numeric($myUS)) { $myDec = 0; } else if ($myUS > 0) { $myDec = 1 + $myUS / 100; } else { $myDec = 1 - 100 / $myUS; } return number_format($myDec,; } Thanks!!
  21. Can you give me an example of how that would help?
  22. Sorta hard to explain what I'm doin but I'll try.. I have a bunch of checkboxes with the value format of id_type.. (i.e. 772280_one) Each id (or group of checkboxes) has 3 different choices for example.. Like so: <input type="checkbox" value="772280_one" /> <input type="checkbox" value="772280_two" /> <input type="checkbox" value="772280_three" /> <input type="checkbox" value="772281_one" /> <input type="checkbox" value="772281_two" /> <input type="checkbox" value="772281_three" /> <input type="checkbox" value="772282_one" /> <input type="checkbox" value="772282_two" /> <input type="checkbox" value="772282_three" /> .....many many more checkboxes with different id's below here as well..... What I was trying to avoid was running a query for each checkbox checked like so: foreach($result as $r){ // run my query for each choice here that selects the data for that rows id // now create a string for the insert here with the new data selected from the rows id } // then finally insert the data into the next table I was trying to just run a single query that selects all the info at once.. And then run another single query to insert all the new data at once.. When I create my string of id's and run them trough the loop it only loops duplicates once.. The example I was trying to avoid is working perfectly except it runs a query for each checkbox checked.. I guess it's ok.. I'm rather new to running queries and I was just trying to optimize them as best I can because I'm planning on having thousands of records to query here.. Who knows, maybe it'll be just fine running a query for each id and then doing one query at the end to insert all that data into the new table.. I'd say at max there could be like 25 ids to loop and query at a time.. What does anybody think? Good to go? or can it be set up better? Thanks!! I hope that explains a bit more about what I'm trying to accomplish..
  23. Ahh I thought that was gonna work! I guess I left some details out.. There's another issue then.. Not all id's are going to be duplicates.. Take this query for example: SELECT * FROM table WHERE event_id IN (772280,772280,772457,772458,772453,772454) I ran your code and it loops all of them 6 times each.. I just need one loop for each id.. Thanks a ton for the suggestion requinix!
  24. I have a query like so: SELECT * FROM table WHERE event_id IN (772280,772280) Is there any way to force that query to loop twice and return two results? I'm looping the $result like so and need two results looped: foreach($result as $r){ // results } I doubt there's a way to do this, but I figured I'd try throwing it out there and see.. Thanks!
×
×
  • 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.