Jump to content

Barand

Moderators
  • Posts

    24,573
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. @maxxd, He is intent on doing this way regardless of attempts to advise otherwise http://forums.phpfreaks.com/topic/298429-imploding-a-multi-dimensional-array/?do=findComment&comment=1522337
  2. Your form needs a submit button. Your select has name='site' therefore the value will be in $_POST['site']
  3. use a function which takes an array as its argument. You can then use the same function for sites, people etc by just passing it a different array. <?php $sql1="SELECT Site_ID, Site_name_1 FROM `Sites`"; $result1=mysql_query($sql1); $site_array = array(); while (list($id, $name) = mysql_fetch_row($result1)) { $site_array[$id] = $name; } function get_options($arr, $current=null) { $opts = ''; foreach ($arr as $k => $v) { $sel = $k==$current ? 'selected="selected"' : ''; $opts .= "<option value='k' $sel>$v</option>\n"; } return $opts; } ?> <html> <body> <select name='site'> <?php echo get_options($site_array);?> </select> </body> </html>
  4. foreach($cars as $a) { $tmp[] = join('||', $a); } $result = join('~', $tmp); echo $result; //--> goat||22||18~pig||15||13~rabbit||5||2~doe||17||15
  5. Then why don't you select STR_TO_DATE(completion_date, '%W, %M %d %Y') from your table so you have the format you need. It really is time you converted those dates in your table - it seems to be popping up often in your posts.
  6. use json_decode($json, true); to get an array as the result.
  7. His original query (from opening post) was ... WHERE STR_TO_DATE(`Completion Date`, '%W, %M %e, %Y') BETWEEN CURDATE() AND CURDATE() + INTERVAL (90) DAY which does convert the date string, but contains an error in the BETWEEN clause (ie next 90 days instead of last 90 days). And the output from STR_TO_DATE() mysql> SELECT STR_TO_DATE('Tuesday, October 6 2015', '%W, %M %e %Y') as date; +------------+ | date | +------------+ | 2015-10-06 | +------------+ is definitely yyyy-mm-dd format and is human-readable, contrary to your statement.
  8. @ginerjm, If you were to RTFM I think you would find it (str_to_date) does create a date in yyyy-mm-dd format mysql> SELECT STR_TO_DATE('Tuesday, October 6 2015', '%W, %M %e %Y') as date; +------------+ | date | +------------+ | 2015-10-06 | +------------+
  9. No. Have another look at my BETWEEN clause. The earlier date must come first. It would be be more efficient to reformat the date once on import instead of in every query.
  10. For last 90 days WHERE ... BETWEEN CURDATE() - INTERVAL 90 DAY AND CURDATE() And GROUP BY should be at the end of the query
  11. The syntax is INSERT INTO `formular_client` (`client_cv`) VALUES ('$actual_image_name') or INSERT INTO `formular_client` SET `client_cv` = '$actual_image_name'
  12. And as none of the OP's forms have an id attribute, and none of his inputs have a form attribute, then this is irrelevant.
  13. You can do that, but if your aim is to reduce the array to a single string then use json_encode $cars = array ( array("Volvo",22,18), array("BMW",15,13), array("Saab",5,2), array("Land Rover",17,15) ); $str = json_encode($cars); echo $str; //--> [["Volvo",22,18],["BMW",15,13],["Saab",5,2],["Land Rover",17,15]] to recreate the array again, you then use $cars = json_decode($str, true);
  14. this line if ($urlFile = "") sets the $urlFile to '' You need the comparison operator "==" and not the assignment operator "="
  15. Does this version work for you - enclosing the search text in single quotes and no escape of the double quotes? UPDATE `testsig` SET `signature` = replace( signature, '<p style="text-align:center;"> </p>', '' ) ; mysql> UPDATE `testsig` -> SET `signature` = replace( signature, '<p style="text-align:center;"> </p>', '' ) ; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
  16. ginerjm told you what was wrong with that line (in reply #4)and re-wrote it for you
  17. You need space between OR and next name $orlogic .="uname='$user' OR "; ^ | space
  18. try $mysqli = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $id = 75; $sql = "SELECT ci.collection_item_number , ci.collection_item_title , ci.collection_item_text , ci.username_id as ownerid , c.comment , c.username_id as userid FROM collection_items ci LEFT JOIN collection_item_comments c ON ci.collection_list_id = c.collections_list_id AND ci.collection_item_number = c.collection_items_id WHERE ci.collection_list_id = ?"; $data = []; $stmt = $mysqli->prepare($sql); $stmt->bind_param('i', $id); $stmt->execute(); $stmt->bind_result($number,$title,$text,$ownerid,$comment,$userid); while ($stmt->fetch()) { if (!isset($data[$number])) { $data[$number] = [ 'title' => $title, 'text' => $text, 'id' => $ownerid, 'comments' => [] ]; if ($comment) $data[$number]['comments'][] = [$comment, $userid]; } else { if ($comment) $data[$number]['comments'][] = [$comment, $userid]; } } ?> <html> <head><title>Sample</title> <style type="text/css"> table { border-collapse: collapse; } tr { vertical-align: top; } th,td { padding: 5px; } </style> </head> <body> <table border="1"> <tr><th>List Number</th><th>Item Title</th><th>Comments</th><th>Posted By</th></tr> <?php foreach ($data as $number => $item) { $span = count($item['comments'])+1; echo "<tr><td rowspan='$span'>$number</td> <td rowspan='$span'>{$item['title']}</td> <td>{$item['text']}</td> <td>{$item['id']}</td></tr>"; foreach ($item['comments'] as $comm) { echo "<tr><td>{$comm[0]}</td><td>{$comm[1]}</td></tr>"; } } ?> </table> </body> </html>
  19. I would agree that if you have the order_item_id then you do not need order id. However, in the case of toppings it could be that item X has a choice of toppings and you want the choice applicable to the particular ordered item. Though I am guessing here about the actual relationship, without knowing the full schema.
  20. Stop calling getTimeStamp() repeatedly. Call it once and store in a variable, then use the variable. That way you always have a consistent timestamp.
  21. Details would be useful. What is the structure of the source table? What is the structure of the destination table? Are you inserting new records with the transferred data, or are you updating existing records? What is your current code?
  22. Can't resist an interesting challenge. This is my interpretation of your problem and a possible solution (Note that the top lines of the two text files need removing prior to processing so they contain just the relevant data) $students= []; $limits = []; $totals = []; $results = json_decode(file_get_contents('result.txt'),1); /*************************************************************** * GET STUDENT DATA * (store classes in score order (desc) for each student) ****************************************************************/ foreach ($results as $sdata) { $tmp = array_slice($sdata,1); // get array of just classes and scores arsort($tmp); $s = $sdata['id_siswa']; $students[$s] = array_keys($tmp); // store classes in order of score $totals[$s] = array_sum($tmp); // get total score for each student } /*************************************************************** * SORT TOTALS ARRAY TO GIVE STUDENT PROCESSING ORDER * (students with highest total scores allocated first) ****************************************************************/ arsort($totals); /*************************************************************** * GET CLASS LIMITS ****************************************************************/ $ldata = file('limit.txt'); foreach($ldata as $line) { list($c,$l) = explode(':',$line); $limits[trim($c)] = trim($l); } /*************************************************************** * ALLOCATE THE STUDENTS TO CLASSES * if highest score class is full, try next until allocated ****************************************************************/ $classes = array_fill_keys(array_keys($limits), []); foreach ($totals as $sid=>$t) { foreach ($students[$sid] as $cls) { if (count($classes[$cls]) < $limits[$cls]) { $classes[$cls][] = $sid; break; // student allocated to class } } } /*************************************************************** * OUTPUT THE RESULTS ****************************************************************/ foreach ($classes as $cls => $studs) { echo "<strong>$cls</strong> " . count($studs) . " students (Limit : {$limits[$cls]})<br>"; echo join(', ', $studs). '<br><br>'; }
  23. You have no closing ")" after the values in the query.
  24. Then you are doing something wrong mysql> CREATE TABLE test_time (thetime TIME); Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO test_time (thetime) VALUES ('01:30:10'),('00:05:00'); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> SELECT TIME_TO_SEC(thetime) as sec FROM test_time; +------+ | sec | +------+ | 5410 | | 300 | +------+ 2 rows in set (0.00 sec)
  25. Use a TIME type field (format hh:mm:ss) for maximum functionality. If you need it converted to seconds use TIME_TO_SEC() function mysql> SELECT TIME_TO_SEC('00:05:30'); +-------------------------+ | TIME_TO_SEC('00:05:30') | +-------------------------+ | 330 | +-------------------------+
×
×
  • 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.