Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. SELECT p.description , pr.size , GROUP_CONCAT(f.flavour SEPARATOR ', ') as flavours , pr.price FROM product p INNER JOIN price pr ON p.id = pr.prod_id INNER JOIN available a ON pr.id = a.price_id INNER JOIN flavour f ON a.flav_id = f.id GROUP BY p.description, pr.size which should give something like this (no data so not tested) +----------------------+----------+-----------------------------------------+---------+ | description | size | flavours | price | +----------------------+----------+-----------------------------------------+---------+ | Shake | 500 | Banana, Chocolate | 26.50 | | Shake | 750 | Mango, Strawberry, Vanilla | 28.90 | | Whey protein prof | 920 | Banana, Strawberry | 26.50 | | Whey protein prof | 5000 | Chocolate, Strawberry | 115.50 |
  2. Any reason why you didn't have a simpler +--------------+ | attendance | +--------------+ | employee_id | | date | | brand | | branch | | shift | | time_in | | time_out | | sales | +--------------+
  3. That is one way NOT to do it. I'd go with something like this Product +-----+--------------------+ | id | description | +-----+--------------------+ | 1 | Shake | | 2 | Whey protein prof | +-----+--------------------+ | Flavour +---------------------------+ +----+-----------------+ | | id | flavour | Price | +----+-----------------+ +----+---------+------+---------+ | 1 | Banana | | id | prod_id | size | price | | 2 | Chocolate | +----+---------+------+---------+ | 3 | Mango | | 1 | 1 | 500 | 26.50 | | 4 | Strawberry | | 2 | 1 | 750 | 28.90 | | 5 | Vanilla | | 3 | 2 | 920 | 26.50 | +----+-----------------+ | 4 | 2 | 5000 | 115.50 | | +----+---------+------+---------+ | | | +-----------------------------------+ | | | Available | | +----+--------+---------+ | id |price_id| flav_id | +----+--------+---------+ | 1 | 1 | 1 | | 2 | 1 | 2 | | 3 | 2 | 3 | | 4 | 2 | 4 | | 5 | 2 | 5 | | 6 | 3 | 1 | | 7 | 3 | 4 | | 8 | 4 | 2 | | 9 | 4 | 4 | +----+--------+---------+
  4. You stand more chance of a response by posting in English on an English-speaking site
  5. Probably you don't have an index on location name so is has to read and compare all rows
  6. <?php if ($databasefield == 1) { // true do something } else { // false do something else } ?>
  7. Only the one that is testing for equality should be "==" To test if a particular bit is set you need to use a logical "and" (&). EG Suppose your variable contains 00000101 // 00000101 // ^ to check if this bit is set use logical "and" with 4 (binary value of the bit) if ($myvar & 4) { // bit is set so do something } PS My name is Barand, not sen. Funnily enough, my name in my posts appears in exactly the same place as your name does in your posts. Strange but true.
  8. the comparison operator is "==". "=" is the assignment operator
  9. Here's my solution <?php include("/animate.class.php"); $anim = new animation('LRRL.LR.LRR.R.LRRL.', 1); echo '<pre>' . join("\n", $anim->animate()) . '</pre>'; ?> animate.class.php: <?php class particle { private $startpos; private $speed; public function __construct($pos,$dir,$speed) { $this->startpos = $pos; $this->speed = $dir=='R' ? $speed : -$speed; } public function getPos($n) { return $this->startpos + $n * $this->speed; } } class animation { private $particles; private $speed; private $size; public function __construct($particleStr, $speed) { $l = strlen($particleStr); $this->size = $l; for ($i=0; $i<$l; $i++) { if ($particleStr[$i] != '.') $this->particles[] = new particle($i, $particleStr[$i], $speed); } } public function animate() { $rows = array(); $n = 0; do { $output = $this->getPositions($n); $rows[$n++] = $output; } while (trim($output,'.')); return $rows; } private function getPositions($n) { $str = str_repeat('.', $this->size); if (count($this->particles) > 0) { foreach ($this->particles as $p) { $pos = $p->getPos($n); if ($pos >= 0 && $pos < $this->size) { $str[$pos] = 'X'; } } } return $str; } }
  10. You know each particles start position, speed and direction. Each time period calculate the new position for each after N periods foreach particle if direction='R' dir = 1 else dir = -1 end if newpos = startpos + N * speed * dir end foreach
  11. If they only ever get a single option, why have an option dropdown at all?
  12. You cannot interact with the user in the middle of a php script so it will have to be javascript. Have you looked at confirm()
  13. Set the value of $attendance_indicator in the code prior to the insert and use "?" instead of the CASE statement $attendance_indicator = ($attendance_status=='Present') ? "1": "0"; $insert_stmt->bind_param('ssssss' ,$shift, $username, ucfirst($agent), $attendance_indicator, $attendance_status, $agent_comments); Alternatively, specify the status before the indicator in the insert column list so it then has a value before you do the CASE for the indicator and you only need 5 parameters as the indicator is a case statement INSERT INTO shift_agent_report ( shift , username , agent , attendance_status , attendance_indicator , agent_comments ) VALUES ( ? , ? , ? , ? , (CASE WHEN (attendance_status = 'Present') THEN '0' ELSE '1' END) , ? ) then $insert_stmt->bind_param('sssss' ,$shift, $username, ucfirst($agent), $attendance_status, $agent_comments);
  14. Could be the web server timing out. Have you tried running the LOAD DATA statement from the MySQL CLI or using a db front end like Mysql Workbench? Failing that, try splitting the csv file.
  15. Bad idea (should be DATE, DATETIME or TIMESTAMP), but I was asking about the `DurationDaysMin` and `DurationDaysMax` fields.
  16. You aren't seriously storing the min and max duration columns as varchar and containing the "+" characters and spaces, are you?
  17. Use LOAD DATA INFILE statement http://dev.mysql.com/doc/refman/5.6/en/load-data.html
  18. you will probably have to replace the "p" with "pm" $time = "9:33p EST"; $dt = new DateTime(str_replace('p', 'pm', $time)); echo $dt->format('H:i:s'); // --> 21:33:00
  19. Every. No quotes around the values in querystrings
  20. Create the tables to be identical in the first place CREATE TABLE table2 LIKE table1
  21. I have found it useful in the past to buffer the output from a php page then save that output to a static html file. I can then email the sample output to a client for approval/comments while still under development on my local pc
  22. Don't put $cat_id in quotes in the href string eg <a href="?cat_id='1'">Click</a><br><br> <?php if (isset($_GET['cat_id'])) { $cat_id = $_GET['cat_id']; $cat_id = mysqli_real_escape_string($con, $cat_id); $query = "SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '$cat_id'"; echo $query; } When the query is output, the value of cat_id contains the quotes SELECT * FROM images JOIN cats ON images.img_category = cats.cat_id WHERE cats.cat_id = '\'1\''
  23. Your column names are enclose in single quotes in that last post and in backticks (correct) in your earlier one. Which is it?
  24. Boompa, FYI Despite the " within another ", this code runs fine (The curlies take care of the inner " ) $record["call"]='abc'; $sql = "INSERT INTO `qsolog` (`call`) VALUES ('{$record["call"]}')"; $db->query($sql) or die($db->error); $sql = "SELECT id, `call` FROM qsolog"; $res = $db->query($sql); $row = $res->fetch_assoc(); vprintf ("ID : %d<br>CALL : %s", $row ); /* OUTPUT *** ID : 1 CALL : abc */
  25. I can't see anything obvious. What was the full error message?
×
×
  • 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.