Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by JonnoTheDev

  1. A temporary table is a table created from the results of a query or a set of queries (nested possibly). They are useful when you cannot return the results you require from a single query on current tables.

    http://dev.mysql.com/doc/refman/5.0/en/create-table.html

     

    However you should be able to return the results you require by altering the sort order on the xpos and ypos fields so:

     

    SELECT object_name, xpos, ypos, from object WHERE proj_id='78' ORDER BY xpos ASC ,ypos DESC LIMIT 1

    SELECT object_name, xpos, ypos, from object WHERE proj_id='78' ORDER BY xpos DESC ,ypos ASC LIMIT 1

  2. That is because your query is writen to do that. MIN is not the way to do this because it will return the minimum values for any records that have a proj_id of 78. You should use a sort query and then limit it to 1 record

     

    SELECT object_name, xpos, ypos, from object WHERE proj_id='78' ORDER BY xpos,ypos ASC LIMIT 1
    

  3. Also static methods are useful for generating objects of different types.

    Lets say we have an application that can connect to 3 different types of databases: sql, mysql, and oracle

    We dont want to have to write conditions in our calling code to determine what type of class to instantiate so we use a static method. The type of object returned could be based on the database connection string, so:

     

     

    // $db could be an instance of classes sql, mysql, or oracle
    $db = dbConnector::connect($connectionString);
    $db->query($query);
    

     

    The dbConnector class may look as follows:

     

    class dbConnector {
       public static function connect($string) {
          // some regex on the connection string
          $result = preg_match(
          switch($result) {
           case 1:
            return new sql($matches[2],$matches[1]);
           break;
           case 2:
            return new mysql($matches[1], $matches[2]);
           break;
           // etc....
          }
       }
    }
    

  4. You dont have to do this with many queries. The way you are generating your objects forces you to do it the way you describe!

     

    Use the same SQL as you mention in the initial post with your unions and joins. This as you say returns all the data you require in 1 go rather than using sub queries in a loop from an initial query. You can generate the objects you require from the data returned by the query using similar code to my post above.

     

  5. Sorry bad code above. Better

     

    class IPFactory {
    
        public static function generate($ipAddress) {
            // database query (WHERE ip=$ipAddress)
            $result = mysql_query("SELECT ");
            $row = mysql_fetch_array($result);
            return array('ip' => new IP($ipAddress), 'device' => new IPDevice($row['field1'], $row['field2'])); 
        }
    }
    
    // usage
    $ipInfo = IPFactory::generate('10.0.0.1');
    $ipInfo['ip']->classMethodInIPClass();
    $ipInfo['device']->classMethodInIPDeviceClass();
    
    

  6. Why not use a factory pattern to create your objects with all data you require.

     

    So if you have an IP class, a device class etc:

     

     

    class IPAssignmentFactory {

     

    public static function generate($ipAddress) {

      // database query (WHERE ip=$ipaddress)

      $query =

      $result = mysql_fetch_array($query)

      return array('ip' => new IP($ipaddress), 'device' => new IPDevice($result['field1'], $result['field2']));

     

    }

    }

     

    $ipInfo = IPAssignmentFactory('10.0.0.1');

    $ipInfo['ip']->classMethodInIPClass();

     

    // etc

  7. You already have it here

    $subtotal = ($_SESSION['cart'][$row['item_id']]['quantity'] * (($_SESSION['cart'][$row['item_id']]['price']))+ $shipping);
    

     

    Your quantity and prices are stored in the session. If you add the shipping, so:

    $_SESSION['shipping']

     

    $subtotal = ($_SESSION['cart'][$row['item_id']]['quantity'] * (($_SESSION['cart'][$row['item_id']]['price']))+ $_SESSION['shipping']);
    

     

  8. You musn't have any MTA (mail transfer agent). See my post above. If you are using Outlook on your PC you have to setup a mail account i.e. POP3 suppliying a mail server, username, password, etc so you can send & receive mail.

    The php mail function() cannot guess this for you!

  9. Never tried from a standalone pc!

    Always developed on *nix systems. Mail server would be sendmail or exim, etc..

     

    Check out mail() on php.net

    If you are a windows user:

    The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket

     

    http://uk2.php.net/manual/en/function.mail.php

  10. Store the users details and date modified in another database table.

    I assume all users have a login and a unique ID.

    For example you may have a table called stockInfo that contains records that users can update via forms to change the level of stock in a shop. To track updates on records you could have a stockUserAudit table containing the stockId as a foreign key from the stockInfo table, a userId for which user updated the stock record and a datetime field to capture the date of modification. You could easily create reports from this structure.

  11. Add mail headers. Also I have sometimes had to use the -f switch (see mail() function) on certain web hosts

     

    	$from = "me@mydomain.com";
    
    	$headers  = "MIME-Version: 1.0\n";
    	$headers .= "Content-type: text/plain;\r\n";
    	$headers .= "X-Priority: 3\n";
    	$headers .= "X-MSMail-Priority: Normal\n";
    	$headers .= "X-Mailer: php\n";
    	$headers .= "From: \"My Company\" <".$from.">\n";
    	$headers .= "Reply-To: \"My COmpany\" <".$from.">\n";
    
    	mail("to@whoever.com","subject","message",$headers,"-f".$from);
    
    

  12. The IP address shown is the IP address assigned to you by your ISP to access the Internet. Obviously your home or work Internet ISP connection is different to you web servers wherever that is hosted. You cannot change your IP address without the use of a proxy. If both your own computer and your server access the web via the same proxy then the IP address will be the same.

×
×
  • 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.