Jump to content

mikosiko

Members
  • Posts

    1,327
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by mikosiko

  1. no clear what exactly are you looking for as a result... if you are looking just for the total number of users in both groups (without duplicates) this will do it SELECT COUNT(DISTINCT user_id) as total FROM group_members WHERE group_id IN (2,17); or are you looking for the list of user_id's (without duplicates) and not matter to which group they belong?... in such case maybe this will work (SELECT user_id FROM group_members WHERE group_id IN (2,17) GROUP BY user_id HAVING COUNT(user_id) = 1) UNION (SELECT user_id FROM group_members WHERE group_id IN (2,17) GROUP BY user_id HAVING COUNT(user_id) > 1)
  2. just to start..... please tell me that you really don't have this code in your php <?php CREATE TABLE `guestbook` (`Guest` INT(70) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY, `Name` VARCHAR(65) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `Message` VARCHAR(200) CHARACTER SET utf32 COLLATE utf32_bin NULL DEFAULT NULL, `Posted` VARCHAR(65) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL) ENGINE = MyISAM CHARACTER SET utf8 COLLATE utf8_bin
  3. you have 2 queries... you can do the same with just 1 query... the rest is just a matter of how you display the results. try to write just the query and modify your code... post back your doubts.
  4. Maybe I should try to clarify a little... unless you have an auto-increment field in your table (as in your case). In general terms NEW will no have any effect (value) in an AFTER INSERT trigger, unless (exception) the same row receive an UPDATE that occurs BEFORE the trigger execution, in such case NEW will show the value of the field of the last UPDATED row ... according to the manual: "You can refer to columns in the subject table (the table associated with the trigger) by using the aliases OLD and NEW. OLD.col_name refers to a column of an existing row before it is updated or deleted. NEW.col_name refers to the column of a new row to be inserted or an existing row after it is updated." that is why the trigger code that I did post works ... confusing?... is not really... MYSQL auto-increment inner functionality is the responsible of this "behavior" ... basically the row is inserted and immediately updated for the auto-increment functionality, hence the AFTER trigger works. And yes, that doesn't work in a BEFORE trigger
  5. what MYSQl version do you have? The trigger that I posted for you (AFTER INSERT and using NEW) does work perfectly
  6. multi_query and prepared statements are not compatible.... prepared statement MUST consist of only a single SQL statement.. as stated on the manual http://www.php.net/manual/en/mysqli.prepare.php
  7. the field table1id doesn't exist in your table mastertable (according to what you posted).. maybe just a typo? this work for me perfectly (tested): DELIMITER $$ CREATE TRIGGER ins_masterid AFTER INSERT ON `table1` FOR EACH ROW BEGIN INSERT INTO mastertable (tablesid) VALUES (NEW.id); // I did replace table1id for tablesid (according to what you posted) and eliminate the auto-increment field (not necessary) END$$ DELIMITER ;
  8. try this (no tested): SELECT * FROM tblStories INNER JOIN tblUsers ON tblStories.stories_owner = tblUsers.users_id AND tblUsers.users_level >= 5 LEFT JOIN tblsComments ON tblUsers.users_id = tblComments.comment_owner_id AND tblComments.comments_status = 2 AND tblStories.stories_id = tblComments.comments_story_id WHERE tblStories.stories_status = 2
  9. you will be much better if you redesign your "weeks" table ... actually it has the infamous "spreadsheet style"... a simple re-design with 3 tables will give you more flexibility and should simplify your queries (using just a JOIN), after that, the generation of a "pivot table" style report is just a matter of display. suggestion: Weeks week-ID [other week related stuff].. take out of here all the p1..p2...etc. Pengs peng-ID points etc..etc WEEK-PENGS this table hold the relation between weeks and pegs, and will not be limited to just 10 pengs as with your current design week-id peng-id with this design all the code (10 or so SQL's) that you previously posted will be reduced to just one query: SELECT weeks.week-id, week-pengs.peng-id, pengs.points FROM weeks JOIN week-pengs ON weeks.week-ID = week-pengs.week-ID JOIN pengs ON week-pengs.peng-ID = pengs.peng-ID
  10. in the original code that you posted... in this line: $result = $mysqli->query($q) or die($mysqli_error($mysqli)); you are mixing OO style ($mysqli->query()) with something like (but no close) to Procedural Style ($mysqli_error()) ... totally wrong maybe what you are trying to do is: $result = $mysqli->query($q) or die($mysqli->error); this is going to trow the error that you are getting ""undefined variable" & Function must not be a string"... if your query is wrong and die() is triggered and fenway post still valid.
  11. 2 options: 1) echo the variable $host before the the connect to check if you really have the value "localhost" 2) write again the line that read $host = "localhost" ... you could have a hidden character there.
  12. this is easier http://dev.mysql.com/doc/refman/5.1/en/create-procedure.html
  13. simple syntax error....
  14. in you update.php file look for this line: change the short tags for long one as in the rest of your scripts. and after that... in your updated.php echo $update before execute the mysql_query to validate it
  15. post some of the combinations that you have tried and explain why they "don't work"
  16. ^^+1 and if you have the privileges to query the INFORMATION_SCHEMA table a simple query could do the "hard" job to spell the columns for you... ready to just copy and paste.....
  17. well... seems to me that you did
  18. sure you tried to say JOIN instead of UNION right?
  19. exactly... hence the error that you had in the beginning ... in a trigger (or stored function) you can't make reference to the table associated to the trigger/function
  20. the answer depend on what exactly are you trying to do.... if you want to update a field based on the NEW values of other fields... then yes you can... but don't use the UPDATE clause... example to test: CREATE DEFINER=`access`@`%` TRIGGER `portal_sosha`.`testTrigger` BEFORE UPDATE ON `portal_sosha`.`transactions` // to calculate the field BEFORE the update (prevent to execute the trigger more than 1 time) FOR EACH ROW SET NEW.tr_transaction_pct_paid_to_company = NEW.tr_transaction_dol_paid_to_ngfg / NEW.tr_premium_or_basis_amount;
  21. the error message is telling you exactly what the problem is: ERROR 1442: Can't update table 'transactions' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.. that is one of the known limitations of stored functions & triggers http://dev.mysql.com/doc/refman/5.0/en/stored-program-restrictions.html
  22. well... there is a working example in the "Users Contributed notes" on the manual... basically you have to extends the MYSQLI_RESULT class http://www.php.net/manual/en/class.mysqli-result.php
  23. quoted with the identifier quote character which is the backtick `character`
  24. A few things caught my attention... here public function __construct($host, $user, $pass, $db){ $this->mysql = new mysqli($host, $user, $pass, $db) // it not should be $this->mysqli to be consistent with the usage after this? or die("Error connecting to the database {$db}"); and this $this->result = parent::query($query); $result = parent::fetch_array($this->result); should be $this->result = $this->mysqli->query($query); $result = $this->result->fetch_array(); and finally... - you are missing a " before Admin" and - LIMIT should be the last part of your select... hence your select could be invalid with those modifications your code works for me
  25. @PFM: Just curious to know why you chose REPLACE instead of the original UPDATE... is not that a call for eventual problems? : - REPLACE is supposed to works like an INSERT but deleting rows if it find duplicates on PK/UK's, and this behavior can trigger ON DELETE CASCADE constraints (if used) causing non desired effects ... or i'm wrong?
×
×
  • 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.