Jump to content

mikosiko

Members
  • Posts

    1,327
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by mikosiko

  1. many here will not call that "help", but spoon feeding ... good luck
  2. $query = mysql_query("SELECT state, city, count(city) as num FROM needs WHERE status='posted' GROUP BY city ORDER BY count(city) DESC"); while ($rows = mysql_fetch_array($query)): $city = $rows['city']; $state = $rows['state']; $citycount = $rows['num']; // num is holding your count by city echo " $city, $state ($citycount)<br><br>"; endwhile In another note, do you want the count only by city (no matter the state) or the count by the pair city-state?... if the last case is what you want you must GROUP BY city AND state
  3. ^+1 also worth to take a look to the many functions at your disposition in php http://php.net/manual/en/function.date.php and if your variable is coming from a mysql resultset, mysql also provide the functions to do that directly in your query http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html
  4. well... mysql count() and php count() function are totally different... why are you using this: $citycount = count(city); if you already counted in mysql? the right way to do it is delete that line and do it in the same way that you did for $city and $state in your loop.
  5. In an early similar question the answer from one of our members was: ... and it apply here too
  6. something that is extremely obvious in your code... in your db.php file you are using the msqli (with an i) API and in the others you are using the mysql (without i) API... you can't mix them in that way. actually the mysql API is not maintained anymore, and it usage discouraged; In replacement you should be using the mysqli or PDO extensions
  7. I'm guessing that you finally need the information from the "class" table, is that is true only one query using a JOIN between "class" and "students" should be enough SELECT class.*, count(students.class) AS ngroup // if you don't need ALL the columns of the guess table don't use "*" and name the columns that you need FROM class LEFT JOIN students ON students.class = class.id // assuming that "class.id" is the same column as students.class. GROUP BY class.id // assuming that "id" is your class table PK ORDER BY ngroup ASC
  8. re-write your query to use explicit JOINS notation (you are using implicit notation for its), and a LEFT JOIN should solve your issue. http://dev.mysql.com/doc/refman/5.5/en/join.html
  9. ^+1 .... you should check Barand first line of pseudo code too, that and the fact that you can also use NOT IN and LIMIT in your query most likely should help you to solve it easily
  10. you are right again... I should have stayed at home today
  11. a modified version that should cover the right scenario pointed out by Dan. granted it is a micro-optimization UPDATE `property` SET `description` = ( CASE WHEN instr(`description`, "é") > 0 THEN replace(`description`, "é", "e") WHEN instr(`description`, "á") > 0 THEN replace(`description`, "á", "a") .... .... ELSE `description` END )
  12. absolutely valid point Dan, I didn't see the query from that angle... if that was the OP objectives as it seems, you are absolutely correct, my code suggestion doesn't work in that scenario; thank you for correct my Uh-oh moment.
  13. why not?... did you tested?.. I did... it does work... maybe you are seeing something that I'm not... enlight us
  14. just don't forget the ELSE part
  15. You don't need to run separated updates (and in a loop)... only ONE update is enough if you use a CASE... example 'UPDATE `property` SET `description` = ( CASE WHEN `description` = "é" THEN "e" WHEN `description` = "á" THEN "a" .... .... ELSE `description` END )
  16. great work guys... congrats to anyone involved in the change.
  17. example from the documentation:
  18. cant't you just write a formula in that cell © to prevent the error message?... something like: =IF(A3>0, B3/A3, 0)
  19. maybe to obvious but, the folder name is "Web" or "web"
  20. read: http://www.php.net/manual/en/language.operators.assignment.php and http://www.php.net/manual/en/language.operators.comparison.php
  21. c'mon it is easy.... the error is in line 1 (pun intended)
  22. now that you found out that the problem was your query, did you try to run your original code with the foreach? // Loop through returned results and store as an array foreach($db->query($sql) as $row) { $e[] = array( 'id' => $row['id'], 'title' => $row['title'] );
  23. did you check here? http://dev.mysql.com/doc/refman/5.1/en/server-logs.html
  24. the original sentence that you posted: $src = "SELECT cat.cat_name, cat.cat_id, prod.prod_id, prod.prod_name, prod.prod_mainImage, prod.prod_model, prod.catalog FROM `myproducts` as prod LEFT JOIN category_assoc AS assoc ON assoc.prod_id = prod.prod_id LEFT JOIN `categories` AS cat ON cat.cat_id = assoc.cat_id WHERE LOWER (prod.prod_name) LIKE '% ".$searchQuery ." %' OR LOWER (prod.prod_description) LIKE '% ".$searchQuery ."%' OR LOWER(prod.prod_model) LIKE '% ".$searchQuery ."%') AND prod.prod_active = '1' ORDER BY prod.prod_model ASC" as an orphan closing parenthesis ... most likely you want the opening one after the WHERE ...
  25. well... the message that you are getting... "I tried the SQL in PHPMyadmin and I get #1064 - You have an error in your SQL syntax" should give you an idea about were to look for the problem, if you can't see the problem at least you should always work with php's error_reporting set to E_ALL (or better a -1) during development, and display_errors should be ON; on a production server display_errors should be OFF and log_errors should be ON; you can do those changes in your php.ini file. Another simple way to debug your code is echoing your sql sentence and look for evident errors on it (you have one in yours)
×
×
  • 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.