Jump to content

Barand

Moderators
  • Posts

    24,609
  • Joined

  • Last visited

  • Days Won

    832

Everything posted by Barand

  1. My suggestion also included putting the hidden field, containing the id, inside the form.
  2. Datetime functions differ greatly between sqlsrv and mysql. I'd start by looking there. Check sqlsrv_error array after calling the query
  3. Barand

    order by

    Without a GROUP BY clause the aggregations will be for the whole table and non-aggregated fields will likely be whatever happened to be in those columns in the first record in the table.
  4. Barand

    order by

    Probably because you are using aggregation functions without a GROUP BY. Does your query only produce a single row?
  5. You don't even need to write a script - a single update query will do it. Add a new DATETIME column (eg 'newdate') to the table to store the new date first. UPDATE dbb SET newdate = STR_TO_DATE(expiredate, '%m-%d-%Y-%H:%i')
  6. try $conn = new mysqli(HOST,USERNAME,PASSWORD,'test'); $data = array(); $sql = "SELECT date, a, b FROM mytable"; $res = $conn->query($sql); while (list($date, $a, $b) = $res->fetch_row()) { $data['A'][] = array($date, $a); $data['B'][] = array($date, $b); }
  7. You have two <form> tags, one at the start of the loop and another just before the submit buttom. Suggest you put the hidden id field after the second and remove the first.
  8. <?php $db = new mysqli(HOST,USERNAME,PASSWORD,'test'); $newarray = [11=>[],12=>[],1=>[],2=>[],3=>[],4=>[],5=>[],6=>[],7=>[],8=>[],9=>[],10=>[]]; $data = []; $trows = ''; /********************************************************** * store data in array by course ***********************************************************/ $sql = "SELECT c.cid , c.courseName , e.startDate , MONTH(e.startDate) as month FROM course c LEFT JOIN eventtbl e USING (cid) ORDER BY cid,startDate"; $res = $db->query($sql); while (list($cid, $cn, $sd, $m) = $res->fetch_row()) { if (!isset($data[$cid])) { $data[$cid]['name'] = $cn; $data[$cid]['events'] = $newarray; } if ($sd) $data[$cid]['events'][$m][] = date('j/m/Y', strtotime($sd)); } /********************************************************** * create table from array data ***********************************************************/ foreach ($data as $cid=>$cdata) { $trows .= "<tr><td>$cid</td><td class='cn'>{$cdata['name']}</td>"; foreach ($cdata['events'] as $dates) { $trows .= "<td class='dt'>" . join('<br>', $dates) . "</td>"; } $trows .= "</tr>\n"; } ?> <html> <head> <title>Example</title> </head> <style type='text/css'> table { border-collapse: collapse; } tr { vertical-align: top; } td, th { font-family: sans-serif; font-size: 9pt; padding: 3px; } td.cn { width: 120px; } td.dt { width: 70px; text-align: right; } </style> <body> <table border='1'> <tr> <th rowspan='2'>Course</th> <th rowspan='2'>Course Name</th> <th colspan='3'>Q1</th> <th colspan='3'>Q2</th> <th colspan='3'>Q3</th> <th colspan='3'>Q4</th> </tr> <tr> <th>November</th><th>December</th><th>January</th> <th>February</th><th>March</th><th>April</th> <th>May</th><th>June</th><th>July</th> <th>August</th><th>September</th><th>October</th> </tr> <?=$trows?> </table> </body> </html>
  9. As I told you, that format doesn't work, echo date('Y-m-d H:i:s', strtotime("06-09-2015-12:00")) //---> 2015-09-06 13:00:00 which is why I suggested DateTime::createFromFormat('m-d-Y-H:i', $expiredate);
  10. You should always store datetimes in a DB as type DATETIME, format YYYY-MM-DD HH:MM:SS. Other formats are largely useless. For now, if you are stuck with that "-" you can $expiredate = "06-09-2015-12:00"; $dtobj = DateTime::createFromFormat('m-d-Y-H:i', $expiredate); $expiretime = $dtobj->getTimestamp();
  11. why the weird datetime format? If that is m-d-y format then just losing the "-" between date and time will work without the preg_replace()s $expiredate = "06-09-2015 12:00"; $expiretime = strtotime($expiredate);
  12. You think? How much testing did you do? mysqli_num_rows() returns a number (which may be 0) and not a boolean true/false result mysqli_error() tales the $conn object as its parameter, not the result object. getting no records returned is not an error, so there would be no message to echo in that event. You need to take a look in the manual more often.
  13. There may be confusion here between basename() and dirname() $dir = " /home/public_html/folder_here/another_folder"; echo basename($dir).'<br>'; //--> another_folder echo dirname($dir).'<br>'; //--> /home/public_html/folder_here
  14. As already shown in my reply ( #8 ) yesterday
  15. There is no universal "correct" way. It all depends on your specific needs.
  16. What file? There is no mention of files in your code. By "previous" do you mean the folder that the file was in before being moved to its current location?
  17. SELECT GROUP_CONCAT(NULLIF(Other_type, 'All_other') as projtype2, ...
  18. try <table border="1"> <tr><th>Rate</th><th>Annual Interest</th><th>Monthly Interest</th></tr> <?php $amount = 50000; for ($i=1; $i<=10; $i++) { $rate = $i/100; $annual = '$' . number_format($amount * $rate, 2); $month = '$' . number_format($amount * $rate / 12, 2); echo "<tr><td>{$i}%</td><td>$annual</td><td>$month</td></tr>"; } ?> </table>
  19. There is a solution to similar problem here http://forums.phpfreaks.com/topic/298003-data-display-in-wrong-column/?do=findComment&comment=1520058
  20. I gave you the code for using your query with Google charts two days ago http://forums.phpfreaks.com/topic/297975-php-encode-to-json-help-with-morrisjs-please/?do=findComment&comment=1520002
  21. http://forums.phpfreaks.com/topic/298020-expects-parameter-1-to-be-mysqli-result/?do=findComment&comment=1520121
  22. That must be the most frequently asked question in the forums. I am surprised that the search you made before posting did not find any results
  23. $loadSession will contain either a valid result object or, if the query failed, the boolean value "false" Your query failed - check the value given by $con->error
  24. You probably get 0000-00-00 because 3/15/2014 is m/d/y and you are trying to convert from d/m/y, so getting invalid dates. Also, you left the "/"s out of your formatting string
  25. You store data for efficiency, not for their appearance to the user. You are confusing relational database tables with spreadsheets. You have your code in between the db and the user, so you can present it any way you want, totally independent of the way it is stored. Use relational joins to get data from several tables with a single query.
×
×
  • 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.