Jump to content

Barand

Moderators
  • Posts

    24,599
  • Joined

  • Last visited

  • Days Won

    829

Everything posted by Barand

  1. You can use "fall through" in a switch statement switch ($diff) { case 0: case 1: case 2: case 3: case 4: case 5: $point = 6; break; case 6: case 7: case 8: case 9: case 10: $point = 4; break; default: $point = 1; } echo $point;
  2. $arr1 = [ [4,5], [7,9,5], [1,2] ]; $arr2 = ['A', 'B', 'C']; $arr3 = ['A' => 123, 'B'=> 456]; $simple = 'xyz'; $txt = "Print simple var like $simple or $arr2[2] or $arr3[B], but complex var needs curlies as in {$arr1[1][2]}"; echo $txt; /**** OUTPUT **** Print simple var like xyz or C or 456, but complex var needs curlies as in 5 */ NOTE: if using $arr3['B'] on its own e.g. echo $arr3['B']; the quotes around 'B' are required (it will work but inefficiently as PHP will first search for a defined constant 'B' and interpret it as a string when one is not found), but not if it is inside a double-quoted string. If you use "$arr3['B']" inside double quotes then it too needs curlies. Simple vars may also need curlies in some cases to prevent ambiguity in the var name e.g. $day = 26; echo "Today is the {$day}th of November"; As a rule, I use curlies around all array and object expressions but not around simple variables (unless required as in the last example)
  3. Because you are using a LEFT join to the grade table then put the condition in the ON clause SELECT s.studentid , s.lastname , c.classname , g.grade , g.period FROM students s INNER JOIN classes c USING (studentid) LEFT JOIN grades g ON s.studentid = g.studentid AND g.period = 3 ORDER BY s.lastname
  4. Insert into the invoice table before the while loop (exclude invoice id field) $query1 = "INSERT into sales_invoice (order_id, customer_id, date_invoiced) VALUES ( ".$order_id.", ".$customer_id.", NOW())"; Use $invoice_id = mysql_insert_id() to get the new id and use that when you insert the invoice lines
  5. Checking for an error message would've revealed that syntax error
  6. Then that was your problem
  7. That is weird! Nether "conversation" nor "members" is a reserved word so the `` should be unnecessary A=B is the same B=A That new query has a definite syntax error - WHERE (c.cid=$q orc.originalid=$q)
  8. You're welcome. As well as making your queries more understandable in terms of both function and structure, those tips will make your queries more efficient.
  9. Where are $username and $password defined in admin.php? Why don't you just store the user level in the session and check that in admin.php instead of re-querying the db?
  10. Then your query $reference = mysql_query("SELECT * FROM contacts"); has failed. Check to see what mysql_error() contains. NOTE: you should not be using mysql_ functions, they are deprecated. Use mysqli_ or PDO instead.
  11. It would seem that the query called by $this->_db->get('users', array($field, '=', $user)); failed and $data is, therefore, not a valid object.
  12. 1. Dont use "... FROM A, B, C WHERE ... " syntax - use explicit joins 2. Don't use SELECT *, specify the columns you need 3. In this case, where you want to list a student even if there is no matching grade record, then you need a LEFT JOIN SELECT s.studentid , s.lastname , c.classname , g.grade FROM students s INNER JOIN classes c USING (studentid) LEFT JOIN grades g USING (studentid) ORDER BY s.lastname edit : grade will be null where there is no matching grade record
  13. [ m ]printf[/ m]produces a link to Unless you use nobbc tags, then it works fine ???
  14. http://php.net/manual/en/function.printf.php
  15. Changing the colour of an area is easy, you just create a mask of the area to be changed. Patterns are much trickier, especially in this situation, as you would have to take scale and perspective into consideration also.
  16. I didn't ask if it worked, I asked what it produced. We cannot see your data from here (believe it or not) so if we don't get information that we ask for we can't help. I wish you luck with the problem.
  17. you may as well remove these two lines, they don't do anything. $_SESSION['username']; $_SESSION['password']; Have you got session_start() at the top of your login page?
  18. What does this query give SELECT id, originalid, member1, member2, removed1, removed2 FROM conversation WHERE (id=1 OR originalid=1)
  19. That was going to be my next post, but i thought I should take you through the debugging steps.
  20. echo '<pre>', print_r($_POST, 1), '</pre>'; what does that give?
  21. What does $stmt->error tell you?
  22. http://php.net/manual/en/language.operators.php
  23. either of these echo number_format($health_percentage, 2); // 2.50 printf('%0.2f', $health_percentage); // 2.50
  24. Depends on what the "something" that you are doing is. If the something that you do to v1 is always independent of what the value of v2 is, then option 1. If, however, that something also depends on the value of v2 then you have to go with option 2.
  25. Store your queries in a string before executing. That way, if you have problems, it is easy to echo the string and maybe spot any errors. $sql = "SELECT c.id c.time as time, c.message as message, c.removed1, c.removed2, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.username as username1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.username as username2 FROM conversation c LEFT JOIN members m1 ON c.member1=m1.id LEFT JOIN members m2 ON c.member2=m2.id WHERE (c.id=$q OR c.originalid=$q) AND ((c.member1=$memberid AND c.removed1='No') OR (c.member2=$memberid AND c.removed2='No')) ORDER BY c.id"; echo "<pre>$sql</pre>";
×
×
  • 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.