Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Depends on what you are trying to achieve. The else{} bit is totally redundant and as $dtA is set to a time in past then the current time will always be greater
  2. First you only want to run the search query when if(isset($_GET['id']) && $_GET['id']!==""){... Second, your search query fails because of a spelling error in the table definition CREATE TABLE IF NOT EXISTS `tbl_barang` ( `id_barang` int(11) NOT NULL AUTO_INCREMENT, `id_kategori` int(11) NOT NULL, `id_kalsifikasi` int(11) NOT NULL, <---- should be klasifikasi `nama_barang` varchar(128) NOT NULL, PRIMARY KEY (`id_barang`) ) Third and more serious You have two dropdowns one gives the classification id with name = "id" other gives category id with name = "id" So how do you know if category or classification was selected? they need to pass separate names in your $_GET. However, no matter which id is selected you search for "WHERE id_barang='$id' ". You need to search for whichever id was passed in the $_GET (category or classification)
  3. You are trying to compare a time value with DateTime object. Two options: $now = new DateTime(); if ($now > $dtA) { ... or if (time() > $dtA->getTimestamp()) { ...
  4. I am saying if you use that syntax you can only get an INNER JOIN (the default join type) It is equivalent to (but less efficient than) SELECT family.Position, food.meal FROM family JOIN food ON family.Position = food.Position
  5. Use the second syntax (ie INNER JOIN .. ON). 1. The first syntax can only be used for the (default) INNER JOIN. If you want a LEFT or RIGHT JOIN you need the second syntax so keep it consistent. 2. The second syntax separates the structure of the query from the selection criteria in the WHERE clause. 3. Your queries will run faster. Strictly you only need to specify table.column where two or more tables contain the same column name thus removing ambiguity about which one to use. Personally I prefer to document the origin of each column using a short table alias (especially if the table name is something like "bacterialogicalculturegrowthstatistitics") so I would write that second query as SELECT c.ID, c.NAME, o.AMOUNT, o.DATE FROM CUSTOMERS c INNER JOIN ORDERS o ON c.ID = o.CUSTOMER_ID;
  6. Sorry, forget the natsort. If you store the results of the query in an array then you will need a custom sort function using strnatcmp EG $sql = "SELECT COUNT(*) as ct, pickup FROM journeys WHERE pickup_type='postcode' GROUP BY pickup HAVING COUNT(*)>=1"; $res = $mysqli->query($sql); while ($row = $res->fetch_assoc()) { $data[] = $row; } usort($data, function($a,$b){ return strnatcmp($a['pickup'], $b['pickup']); }); echo '<pre>'; foreach ($data as $row) { printf ('%-4s %d<br>', $row['pickup'], $row['ct']); } echo '</pre>'; /* OUTPUT EXAMPLE************************ E1 4 E2 2 E10 3 E11 1 **************************************/
  7. I wonder if it because you are only selecting "SUM(num) as num" (Again)
  8. you could store the results in an array then use natsort $arr = array ( 'E1', 'E10', 'E11', 'E12', 'E13', 'E2', 'E3', 'E4' ); natsort($arr); echo '<pre>',print_r($arr, true),'</pre>'; /* OUTPUT ************************* Array ( [0] => E1 [5] => E2 [6] => E3 [7] => E4 [1] => E10 [2] => E11 [3] => E12 [4] => E13 ) **************************************/
  9. Assuming a database structure like this mysql> SELECT * FROM room; +--------+---------+------------+--------------+ | roomid | hotelid | room_title | normal_price | +--------+---------+------------+--------------+ | 1 | 1 | Geranium | 50 | | 2 | 1 | Delphinium | 50 | | 3 | 1 | Rose | 70 | +--------+---------+------------+--------------+ mysql> SELECT * FROM price; +---------+--------+-------+------------+------------+ | priceid | roomid | price | start_date | end_date | +---------+--------+-------+------------+------------+ | 1 | 1 | 60 | 2014-02-02 | 2014-03-29 | | 2 | 2 | 60 | 2014-02-02 | 2014-03-29 | | 3 | 3 | 75 | 2014-02-02 | 2014-03-29 | | 4 | 1 | 90 | 2014-03-30 | 2014-04-02 | | 5 | 2 | 90 | 2014-03-30 | 2014-04-02 | | 6 | 3 | 105 | 2014-03-30 | 2014-04-02 | | 7 | 1 | 65 | 2014-04-03 | 2014-06-15 | | 8 | 2 | 65 | 2014-04-03 | 2014-06-15 | | 9 | 3 | 80 | 2014-04-03 | 2014-06-15 | +---------+--------+-------+------------+------------+ mysql> SELECT * FROM roombooking; +----+-----------+--------+-------------+ | id | bookingid | roomid | bookingdate | +----+-----------+--------+-------------+ | 1 | 123 | 1 | 2014-02-01 | | 2 | 123 | 1 | 2014-02-02 | | 3 | 123 | 1 | 2014-02-03 | +----+-----------+--------+-------------+ then the sort of query you would need is SELECT rb.bookingid , r.room_title , rb.bookingdate , IFNULL(p.price, r.normal_price) as price FROM roombooking rb INNER JOIN room r USING (roomid) LEFT JOIN price p ON rb.roomid = p.roomid AND rb.bookingdate BETWEEN p.start_date AND p.end_date WHERE rb.bookingid = 123 ORDER BY bookingdate; giving +-----------+------------+-------------+-------+ | bookingid | room_title | bookingdate | price | +-----------+------------+-------------+-------+ | 123 | Geranium | 2014-02-01 | 50 | | 123 | Geranium | 2014-02-02 | 60 | | 123 | Geranium | 2014-02-03 | 60 | +-----------+------------+-------------+-------+
  10. echo date ('j F, Y', strtotime($row['event_date'])); or $dt = new DateTime($row['event_date']); echo $dt->format('j F, Y');
  11. If there is always a different weekend price then you might want to to hold both price in the price record. Alternatively, hold two (or more) records for every week of the year. Room ----------- room_id hotel_id room_title Price ----------- id room_id week_price wkend_price start_date end_date This allows you price file dates to define high,mid and low-season prices and also special prices such as Easter Weekend, Christmas and New Year. How you match the prices to the rooms will depend on the structure of your bookings table
  12. But all it does it give you problem of maintaining two copies. Which is the reason for your post. Haven't you heard of SQL JOINS?
  13. A couple of minutes Googling gave $(function() { $( "#datepicker" ).datepicker({dateFormat: 'dd/mm/y'}); }); However, I prefer to use "d-M-y" format for datepickers. It's unambiguous about which is the month and which is the day (unlike 04/05/14) and it still works fine with strtotime() unlike d/m/y format
  14. That is what Ch0cu3r is already suggesting in his last post (#10), with the added benefit that his code sanitizes the user input
  15. If you already hold the user_name, pass_word and user_level in the staff_record, why would you want to duplicate it in the login records?
  16. No, it doesn't mean that. You can assign static values. But it is a waste of time if you then put them in a subquery and just select an aggregation of the counts. $sql = " SELECT 'PX' AS MySite2, COUNT(URL) AS num FROM pox_topics WHERE URL = :MyURL UNION ALL SELECT 'PX' AS MySite2, COUNT(URL) AS num FROM people WHERE URL = :MyURL UNION ALL SELECT 'GZ' AS MySite2, COUNT(Taxon) AS num FROM gz_life WHERE Taxon = :MyURL "; $stmt = $pdo->prepare($sql); $stmt->bindParam(':MyURL',$MyURL,PDO::PARAM_STR); $stmt->execute(); while ($row = $stmt->fetch()) { $Site = $row['Site']; $Total = $row['num']; switch($Total) { case 1: // etc } }
  17. have you tried $picture = $row['picture']; $image = "<img src='image/$picture' height='100' width='100' />"; followed by <td><?php echo $image;?></td>
  18. A LEFT JOIN B ---> Returns all records in A with data from B where there is a match, otherwise null values from B A INNER JOIN B ---> Ony returns rows where there is matching data in both A and B
  19. Which table? No transactions or no users?
  20. When storing dates use column type DATE, format YYYY-MM-DD. DD/MM/YYYY is as much use in a database as a chocolate teapot. You can't compare dates, sort them or use date time functions with that format.
  21. it should now look something like this $sql = "SELECT DISTINCT date FROM attendance ORDER BY DATE"; $res = $db->query($sql); // mysqli query while ($row = $res->fetch_row()) { $dates[] = $row[0]; } /*********************************** * Table headings * ************************************/ $emptyRow = array_fill_keys($dates,''); $emptyRow['P'] = 0; $emptyRow['A'] = 0; // format dates foreach ($dates as $k=>$v) { $dates[$k] = date('d-M', strtotime($v)); } $heads = "<table border='1'>\n"; $heads .= "<tr><th>Name</th><th>" . join('</th><th>', $dates) . "</th><th>Present</th><th>Absent</th></tr>\n"; /*********************************** * Main data * ************************************/ $sql = "SELECT date, staffname, status FROM attendance ORDER BY staffname"; $res = $db->query($sql); $curname=''; $tdata = ''; while (list($d, $sn, $s) = $res->fetch_row()) { if ($curname != $sn) { if ($curname) { $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; } $rowdata = $emptyRow; $curname = $sn; } $rowdata[$d] = $s; $rowdata[$s]++; } $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; $tdata .= "</table\n"; ?> <html> <head> <style type="text/css"> td,th { text-align: center; padding: 5px; } table { border-collapse:collapse; } </style> </head> <body> <?php echo $heads; echo $tdata; ?> </body> </html>
  22. In SQL you would need FROM_UNIXTIME() function first, then you can format it mysql> SELECT DATE_FORMAT(FROM_UNIXTIME(1390146482), '%d/%m/%Y') as date; +------------+ | date | +------------+ | 19/01/2014 | +------------+
  23. quickest way is to run this query TRUNCATE TABLE bloging
  24. I expected you would remove the lines you added last time since you no longer want the totals by date, despite your earlier post:
  25. This may help http://simplehtmldom.sourceforge.net/
×
×
  • 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.