Jump to content

CheesierAngel

Members
  • Posts

    105
  • Joined

  • Last visited

    Never

Everything posted by CheesierAngel

  1. Found some temporary solution, still all suggestions welcome !! [code] <?php /* ... */                 $lastAssigned = ""; foreach($newCustomers as $newCustomer) { print $newCustomer . '\n'; /* Gather Online Operators With The Fewest Assigned Customers */ $sql = <<<SQL SELECT u.id as `operatorId`, COUNT(a.customer_id) as `assignments` FROM users u LEFT JOIN assignments a ON a.user_id = u.id WHERE u.id <> 0 AND u.role_id = 3 AND u.active = 1 AND u.online = 1 $lastAssigned                                                //-> Extra check GROUP BY operatorId ORDER BY assignments ASC SQL; $results = $cCustomer->query($sql); /* Assign New Customer To Operator */ if(!empty($results)) { $operatorId = $results[0]['u']['operatorId']; if(isset($results[1])) {                                            //-> last operator may not be used (if there are more then 1) $lastAssigned = "AND u.id <> $operatorId"; } $sql = <<<SQL INSERT INTO assignments VALUES($newCustomer, $operatorId) SQL; $cCustomer->query($sql); $sql = <<<SQL UPDATE users SET tsAssigned = NOW() WHERE id = $operatorId SQL; $cCustomer->query($sql); } } /* ... */ [/code]
  2. Hi, i really don't know which forum to post this in but i got a mysql php problem. I would like to calculate the number of assigned customers to an operator and link the new customers to the operator who has the fewest customers assigned too. I already wrote some code but the problem is that before the insert is executed the new count calculation is already performed... So if there are 3 new customers, they will all three be assigned to one operator? I already tried to use LOW_PRIORITY and HIGH_PRIORITY inside my queries but the MySQL server doesn't support this yet. (can't upgrade because i don't have the access to do so) I rather do not wanna use a sleep function because if the server is busy there might be a chance the problem occurs again. Any suggestions ? [code] <?php /* ... */ foreach($newCustomers as $newCustomer) { print $newCustomer . '\n'; /* Gather Online Operators With The Fewest Assigned Customers */ $sql = <<<SQL SELECT u.id as `operatorId`, COUNT(a.customer_id) as `assignments` FROM users u LEFT JOIN assignments a ON a.user_id = u.id WHERE u.id <> 0 AND u.role_id = 3 AND u.active = 1 AND u.online = 1 GROUP BY operatorId ORDER BY assignments ASC SQL; $results = $cCustomer->query($sql); /* Assign New Customer To Operator */ if(!empty($results)) { $operatorId = $results[0]['u']['operatorId']; $sql = <<<SQL INSERT INTO assignments VALUES($newCustomer, $operatorId) SQL; $cCustomer->query($sql); $sql = <<<SQL UPDATE users SET tsAssigned = NOW() WHERE id = $operatorId SQL; $cCustomer->query($sql); } } /* ... */ ?> [/code] The query executions may look strange but this code is written inside the CMS cakePHP. (There are no syntax errors!) If you liked some explanation on some line, just ask ... Thanks a lot
  3. You could use some PEAR packages for that: - [url=http://pear.php.net/search.php?q=PDF&in=packages&x=0&y=0]http://pear.php.net/search.php?q=PDF&in=packages&x=0&y=0[/url]
  4. Please set your code between  [ code ] and [ /code ] tags. This makes its beter readable for us. (without the spaces!)
  5. That would be javascript that manipulates the statusbar message. ??? But don't know it is even possible in combination with the PHP header() function
  6. Try doing this: [code] <?php function check_city($name = null) {     if(!empty($name)) {       $checkname = mysql_query("SELECT * FROM users WHERE cityname = '$name'");       $namecheck = mysql_num_rows($checkname);       if ($namecheck > 0){ $reason = "-The name of the city you choose have been taken already<br>"; header("Location: index.php?page=register&reason=$reason");       }       // What if the name does not exists ?       return;     }   $reason = "-Your City must have a name, please fill in the City name field<br>";   header("Location: index.php?page=register&reason=$reason"); } ?> [/code]
  7. So the code is never executing the inside of the if(is_uploaded_file()) ? or are there stille errors generated ?
  8. You shouldn't write on the links.php page the <html> tags. The links.php should look like this (nothing more, nothing less): [code] <?php if($_POST['cmd'] == "link1") {   header("Location: http://www.coolgorilla.com/images/banner.png"); } ?> [/code] Modification: This because the user accessing this page will never see this page... PHP gave you the error because you wanted to write/transmit some header information to the user. [code] <html> <head>  <!-- And here is your header output to the user -->   .... </head> <body> <!-- Here is some information you are transmitting to the user -->   <?php     if(...) {       /*         * Sending again some header information after the headers where already send by the html header tag         * and after you already transfered some content to the user by the <body> tags.       */       header(...);  // Nothing may be outputted already to the user when using this function !!!     }   ?>   </body> </html> [/code]
  9. Do you have write access to the folder you're uploading your files ?
  10. The idee to seperate your error handling from all other classes is to create a class specially for this. Now you could make a class errors or something like that that will keep all your generated errors into a database (by using your database class) or error log file. And on every page of your application/site you could aks the errorClass the latest error to display if any new errors where added. something like: [code] <?php require_once('error.class.php'); require_once('database.class.php'); $cError = new Error(); $cDatabase = new Database(); $cDatabase = new Database('databaseName'); if($error = $cDatabase->getErrorMessage()) { $cError->add(ERROR_CRITICAL, $error); } ?> [/code] And you could add in your pages header or footer: [code] <?php if($cError->newError()) {   $echo "<font color='red'>" . $cError->lastError() . "</font>"; } ?> [/code] And indeed in your dbConfiguration.inc.php you put all your configurations. You should know that programming OO is to extract all specific functionalities into an object/class and only these specific functionalities. So if you create a database class you should only create the functionalities that concern databases into this class. And so on ...
  11. There is a ) to much after the $_FILES[][] and add it again at the end. It should be: [code] <?php if(!preg_match('/^((\w)(.[pdf|ppt]))$/', $_FILES[$userfile]['name'], $match = array())) { // ... } ?> [/code]
  12. Show me the code you are using now ... (put it between the code tags [ code ][ /code ], without the spaces)
  13. There is missing a " at the begining of the header() function. It should be: [code] <?php <?php if($_POST['cmd'] == "link1") {   header("Location: http://www.coolgorilla.com/images/banner.png"); } ?> [/code]
  14. create a script inbetween your link-button (or form) and your actual script. Linkspage: [code] <form action="links.php" method="post">   <input type="hidden" name="cmd" value="link1"> <input type="submit" value="GoToThisLink"> </form> [/code] Your script inbetween: <?php if($_POST['cmd'] == "link1") {   header(Location: http://www.blahblah.com"); } ?>
  15. There is a nice function for things like that, take a look at the php manual (f_open): - http://php.belnet.be/manual/en/function.fopen.php Or if you google for a tutorial on this you'll find alot of these tuts.
  16. [quote author=Daniel0 link=topic=116816.msg476227#msg476227 date=1164896617] Cheesier Angel: Imagine this filename: mysql.db.php That would make: $completeName = "mysql.db.php"; $filename = "mysql"; $ext = "db"; [/quote] Is true, but if you adjust the regex this should be no problem.
  17. You should code your class on a different approach: What should this class do ? - Create a connection - Execute queries with the made connection - Close your connection if asked. What shouldn't this class do? - Error handling !!! - Configuration !!! [code] <?php require_once('dbConfiguration.inc.php'); class database {   private $config = $GLOBALS['dbConfig'];   private $db = null;   public $errorMessage = null;     function database($dbName) {     $this->db = mysql_connect($this->config['dbHost'], $this->config['dbUser'], $this->config['dbPassword'])     or $this->errorMessage = mysql_error();     if($this->db) {       mysql_select_db($dbName, $this->db) or $this->errorMessage = mysql_error();     }   }   function sqlClose() {   mysql_close($this->db)or $this->errorMessage = mysql_error();   }   function sqlQuery($query) {     $results = null;     $results = mysql_query($query, $this->db) or $this->errorMessage = mysql_error();     return $results;   }   function getErrorMessage() {     return $errorMessage;   } } ?> How to use this class: <?php require_once('database.class.php'); $db = new database('DatabaseName');  // Makes connection // Your script that uses the class chooses whatever to do with the generated errors !!! if($error = $db->getErrorMessage()) {   exit($error); } $query = "SELECT * FROM table"; if(!$results = $db->sqlQuery($query)) { // Again: Your script that uses the class chooses whatever to do with the generated errors !!! exit($db->getErrorMessage()); } if(!$db->sqlClose()) {   // And again: Your script that uses the class chooses whatever to do with the generated errors !!! exit($db->getErrorMessage()); } /* This script does not wanna know how the connection is made, does not wanna know the db connection link !!! This script handles the database errors output !!! .... */ ?> [/code]
  18. This is because your user you are using to log into your database server has not the correct privileges to do so. You should contact your db administrator to get the create database privileges for your user.
  19. [quote author=brown2005 link=topic=116824.msg476216#msg476216 date=1164895917] why does it have to have the html bit init.... [/quote] It does not have to have the html bit init. You could do it like you want do it. For example: [code] <?php $word = "cabbage"; ?> <table> <tr>   <th>TheTableHeader</th> </tr> <?php for ($i=0;$i<strlen($word);$i++): ?><tr>   <td>     <?php echo $word{$i}; ?>   </td> </tr><?php endfor; ?> </table> ?> [/code] This works as well. And there are so many more possibilies to do this. Just use the one you prefer. [quote author=brown2005 link=topic=116824.msg476216#msg476216 date=1164895917] what happens if i want a boder or want to put it in a form or something..? [/quote] This is just an example of how you could do this, this is not the solution like you would like it. This shows you how you can do things like this. Use the same logic combined with what you want and you should be able to code what you want. If you liked an entire solution than ask in the freelance forum ...
  20. [quote author=taith link=topic=116821.msg476199#msg476199 date=1164894867] this isnt tested... but it should work... foreach is MUCH faster and easier with arrays :-) [code] <? $checkboxArray = array( 1=>"$rigger", 2=>"$anhugger", 3=>"$systemfacade"); foreach($checkboxArray as $k => $v){ if($v == "on") $checkboxArray[$k] = "YES"; else $checkboxArray[$k] = "NO"; } ?> [/code] [/quote] And the shortest way to do: [code] <?php $checkboxArray = array( 1=>"$rigger", 2=>"$anhugger", 3=>"$systemfacade"); foreach($checkboxArray as $k => $v){   $checkboxArray[$k] = $v == "on" ? "Yes" : "No"; } ?> [/code]
  21. What database server are you using? MySQL, MsSQL, ... ? You should use the exact same queries as you would use in your database server to create a database. [code] <?php // If you're using MySQL // -- Make sure your user you are using to log into the databaseserver has the proper rights to create a database and user !!! $db = mysql_connect('yourHost', 'yourUser', 'yourPassword'); mysql_query('CREATE DATABASE mydatabasename'); .... ?> [/code]
  22. If you have the permissions to read the file, yes you can.
  23. [code] <?php $word = "cabbage"; $output = <<<HTML   <table>     <tr><th>Letters</th></tr> HTML; for ($i=0;$i<strlen($word);$i++) {   $output .= "<tr><td>$word{$i}</td></tr>"; } $output .= <<<HTML   </table> HTML; echo $output; ?> [/code]
  24. You could try a different approach to extract the extention of the file: [code] <?php if (is_uploaded_file($_FILES['user_file']['tmp_name'])) { if(!preg_match('/^((\w)(.[pdf|ppt]))$/', $_FILES[$userfile]['name']), $match = array()) {   $message="File is not a PDF or Powerpoint file. Please try another file.<br>";   include("file_manager.inc");   exit(); } $completeName = $match[0]; $filename = $match[1]; $ext = $match[2]; } ?> [/code]
×
×
  • 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.