Jump to content

Barand

Moderators
  • Posts

    24,572
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. I agree with ch0cu3r. The data in tabe1 is correctly normalized and you should keep it like that. If you want to display the data in the format of table2, do it on output after querying table1.
  2. Use DateTime class. $startTime = '13:30:00'; $endTime = '14:00:00'; $dt1 = new DateTime($startTime); $dt2 = new DateTime($endTime); $diff = $dt1->diff($dt2); echo $diff->format('%h:%I'); //--> 0:30
  3. Both I and gizmola have given you the correct syntax. What's your problem?
  4. $summary = substr(strip_tags($text),0, 200); echo $summary; maybe?
  5. Brought on by storing the markup with the data. Solution: Don't.
  6. Your first challenge is to look at the data you need to store and the processes involved and design a relational database model that supports both.
  7. If it's not correct, what happens? Do they try again until they get it right, so everyone finally finishes the test with 100% correct?
  8. Have you forgotten the ".=" and just used "$results ="
  9. You said that there was already a WHERE clause. Have you added extra conditions to gizmola's WHERE clause using AND? Can you post the actual query you are now running.
  10. Not sure prepare and multiple insert syntax work together. Try $query = "INSERT IGNORE INTO blogTags (tag) VALUES (?)"; $stmt = $this->db_connect->prepare($query); foreach($this->blogTags as $tag){ $stmt->bindValue(1, $tag, PDO::PARAM_STR); print "param: $param<br /> tag: $tag<br />"; $stmt->execute(); }
  11. That returns the value then increments (post-increment). Either use ++$param or start with a value of 1 instead of zero.
  12. to round x to the nearest multiple of y result = round(x/y) * y (eg round(563/25) * 25 = 575) If you want to round down as in your example, use floor() instead of round()
  13. As Gizmola said in his reply UPDATE product p INNER JOIN ( SELECT product_id, SUM(price) as tot -- you FROM -- would ( -- need SELECT product_id, price FROM product_a -- these UNION ALL -- eight SELECT product_id, price FROM product_b -- lines ) ab -- of the GROUP BY product_id -- query ) tots ON p.id = tots.product_id SET p.total = p.total + tots.tot;
  14. Yes. If $result is the result from your query execution, then something like $row = $result->fetch_assoc(); echo $row['total']; // print the total
  15. A query can find no records without failing, it's a perfectly normal result. You need to check the number of rows in the results.
  16. Instead of output buffering, use pagination with mysql LIMIT clause. http://lmgtfy.com/?q=mysql+pagination
  17. The query string needs to be enclosed in double quotes, not single, if you want to expand variable values in the string. Table and column names should not be in quotes $insert = "INSERT INTO XXXXXXXXXX (ID, FirstName, LastName, City, State) VALUES (NULL,'$FirstName','$LastName','$City','$State')";
  18. But, should you want to update regardless, assuming you add a "total" column to the product table UPDATE product p INNER JOIN ( SELECT product_id, SUM(price) as tot FROM ( SELECT product_id, price FROM product_a UNION ALL SELECT product_id, price FROM product_b ) ab GROUP BY product_id ) tots ON p.id = tots.product_id SET p.total = p.total + tots.tot; If you combine the a and b tables as suggested then UPDATE product p LEFT JOIN ( SELECT product_id, SUM(price) as tot FROM product_ GROUP BY product_id ) tots ON p.id = tots.product_id SET p.total = p.total + tots.tot;
  19. If I were you I wouldn't store the product total at all. Just calculate it from a query when required. Don't store derived data in a database. Also, why two tables, a and b, with identical structures. Have a single table with an extra column to identify a and b. DECIMAL type is better option than FLOAT for prices. If you do store the product total, you will need a column for it which you don't currently have according to your model.
  20. The last line of the query looks odd ...ORDER BY sala_ocupacao.`id_ocup`id_ocup;'
  21. your code to create the array $car = array(); $car["vw"] = array( "name" => "volkswagen"); $car["tyta"] = array( "name" => "toyota"); will give you Array ( [vw] => Array ( [name] => volkswagen ) [tyta] => Array ( [name] => toyota ) ) It would be better and simpler to $car = array(); $car["vw"] = "volkswagen"; $car["tyta"] = "toyota"; giving Array ( [vw] => volkswagen [tyta] => toyota ) But why not just give them a dropdown menu of valid types to select from
  22. I was thinking Imperial Purple, but then Gold.
  23. No, you don't want it to look like that. You should not use "SELECT * " and numeric values should not be quoted. What is the relationship between "start" and "end" that you pass to your script via the URL and "bidStatus" and "department"
  24. The last insert id is only available for the current connection. You need to get it and store it ($_SESSION) as soon as possible after the insert. When the script ends the connection closes automatically
  25. Change your single quotes to double quotes and vice versa
×
×
  • 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.