Jump to content

Vebut

Members
  • Posts

    54
  • Joined

  • Last visited

Everything posted by Vebut

  1. Shouldn't a LEFT JOIN result as NULL if there are no rows? Is there something that you think might cause my problem in the query above? The query is identically to the "real deal" except for the names and columns. I'll post complete structure later if it is necessary with sample data.
  2. Hello! I'm trying to calculate a total sum from 3 different tables while grouping by a fourth, but my result vary and is not very accurate in some cases. I'm hoping for some help with understanding whats causing this problem. I've got 3 tables collecting data, 2 of these has a relation and the third is a standalone. This query will return a total that is many times too high for the first result, but the following 9 results are correct. The thing is that its only the first result for this specific table4 reference (1) that has results in table3. So I'm guessing the GROUP clause might be the cause of this problem. table1 is referenced by table5.id table2 is referenced by table1.id table3 is referenced by table5.id table4 is referenced by a given value table5 is referenced by table4.id SELECT DISTINCT SUM( IF(ISNULL(table1.id), 0, (table1.col1 + table1.col2) * table1.col3) + IF(ISNULL(table2.id), 0, table2.col1 * table2.col2) + IF(ISNULL(table3.id), 0, (table3.col1 - table3.col2) * table3.col3) ) AS total, table4.name AS name FROM table4 INNER JOIN table5 ON table5.reference = table4.id LEFT JOIN table1 ON table1.reference = table5.id AND YEAR(table1.timedate) = 2011 LEFT JOIN table2 ON table2.reference = table1.id LEFT JOIN table3 ON table3.reference = table5.id AND YEAR(table3.timedate) = 2011 WHERE table4.reference = 1 GROUP BY table4.id ORDER BY total DESC LIMIT 10
  3. These users are system administrators. So they require it, but I need them to be able to drop databases for their sections (prefix).
  4. Vebut

    Select

    The last post should have the highest incremented value. Timestamps can be manipulated so I would rather use the increment before using the timestamp (as these may not be unique). Unless you want to find the latest car by it's release date.
  5. Vebut

    Select

    Do you have an increment value (id?) for each car, or maybe a timestamp? SELECT * FROM table ORDER BY id DESC LIMIT 1
  6. How would I do that? My usual process is to use PHPMyAdmin to create users with all privileges on their prefix. I've attached some screenshots to show my current setup for a new user "demo", that also has the same problem. [attachment deleted by admin]
  7. I’ve setup all privileges for a database user on prefix\_%. This user can create databases and tables for the prefix but not drop databases. I’ve tried to fix this but unless I grant global privileges for this user the DROP command is unavailable. As I grant the global drop privilege all databases (global) become visible for this user (as it should I guess), but I need this user to be able to drop databases for the specific prefix and not be able to touch/see the other databases. User harry Database prefix\_%, Grant No, Privileges All Privileges, Table specific privileges No. Still this user can create databases, but not drop. Why? I’m sure I’ve missed something as the other users do not have this problem.
  8. I solved it by grouping by project id: GROUP BY projects.id
  9. No I've tried using phpmyadmin but online one result is returned. Can it be the LEFT JOIN clause that is causing this? The table 'reports' does not neccessary contain any records related to the projects.
  10. Well, ':id' is a defined variable that can be used with the PDO library using PHP: <?php $projects = $this->pdo->prepare(" SELECT projects.name AS name, projects.id AS id, SUM(reports.amount * reports.price) AS total, COUNT(reports.user) AS users FROM projects LEFT JOIN reports ON reports.project = projects.id WHERE projects.customer = :id GROUP BY reports.user ORDER BY projects.name ASC "); $projects->bindValue(':id', $id, PDO::PARAM_STR); $projects->execute(); ?> The query returns a project and the projects are allways connected to the customer I'm browsing, so that should not be the problem. Edit: $id contains the customer id.
  11. Hi, I'm having some trouble with a query that is supposed to return all 'projects' connected to a specific 'customer', but only one is returned. SELECT projects.name AS name, projects.id AS id, SUM(reports.amount * reports.price) AS total, COUNT(DISTINCT reports.user) AS users FROM projects LEFT JOIN reports ON reports.project = projects.id WHERE projects.customer = :id ORDER BY projects.name ASC There are several projects on each customer but this query only returns one of them. Also, the returning result does not seem to be affected by the ORDER BY clause as a project called "Port" is returned even though I have other projects that is supposed to be indexed before it (e.g "General"). What am I doing wrong? // Thanks, Daniel
  12. PHP is a serverside language, meaning that it can only be used when a request is made to the server.
  13. There are a couple of ways to count the characters in a string (If i get your question right): 1. Use a for loop with a counter and check to see if each string index is accessible. (Have a look at "{x}" in the string manual). 2. Use regular expressions to match each character 3. Use string length function, strlen() - very simpel and very fast 4. Explode the string and count array posts. Look at str_split().
  14. The field is only hidden from the user. You can allways access the value of a hidden field in php just as you would with a normal one.
  15. mysql_select_db("***, $connection"); should be mysql_select_db("***", $connection);
  16. Ok, now I've got the Mail class working but when using factory I get a fatal error: Edit: Never mind, I installed the Net_SMTP package as well and now its working just fine. Thanks for all the help!
  17. I installed pear (go-pear.bat) and then installed the mail package using command line: "pear install mail" but when I try to use the Mail class inside of my application it can not locate the class. SPL should load it right?
  18. I'm currently working on a newsletter application which is installed on a windows 2003 server running apache. This server is scheduled to run a script every 5 minutes that will send an email to 10 individuals during each iteration. It all works fine when sending to emails registered with our mail server but when sending to external addresses I get a 550 error from the smtp. I've setup these settings in php.ini: Is there something obvious i'm missing here? Thanks! Edit: Not IIS, its apache
  19. I can't seem to connect to a public database using the http address as dbq parameter.
  20. I uncommented the 'extension=php_pdo_odbc.dll' and now it seems to work just fine. Thank you!
  21. As you can see that is exactly where I got my code from. The DSN is identical. @ JustLikeIcarus: I changed the directory separators to '/' instead and now that part seems to work just fine. Now I get this error message: Is there a driver I have to install before I can connect to msaccess files?
  22. Hi, I've been trying to connect to a .mdb file for some time now without success. Been following a couple of tutorials found on google but they all end up with the same error message. <?php $pdo = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\xampp\htdocs\access\test.mdb;Uid=Admin"); var_dump($pdo->errorInfo()); ?> I get this error message What am I doing wrong? // Daniel
×
×
  • 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.