-
Posts
3,584 -
Joined
-
Last visited
-
Days Won
3
Everything posted by JonnoTheDev
-
Look closer get_matches = mysql_query Should be $get_matches = mysql_query
-
and what is the code on minifixtures2.php line 69
-
Adding to a database utilizing PHP and Javascript
JonnoTheDev replied to jonoc33's topic in PHP Coding Help
AJAX - look it up -
Why is speed an issue with such a code example? There are loads of methods for constructing a string as above, implode(), sprintf(), printf() are some functions that could do it? Are you running PHP on a 286 pc?
-
What results are you getting?
-
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
-
Then I would use a temporary table
-
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
-
why use regular methods and not always static?
JonnoTheDev replied to next's topic in PHP Coding Help
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.... } } } -
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.
-
[SOLVED] Newbie question about RSS feeds and how to use them
JonnoTheDev replied to Prodigal Son's topic in PHP Coding Help
Most newer browsers will parse RSS if it is valid XML. Browse to your XML file i.e http://www.yourdomain.com/rss.xml and see if your feeds display properly. You could also get a reader such as RSS Owl and import a new feed with your URL to check its correct. Once correct put a link on your website to the xml file and users who want to use your feed will do the rest. -
Is the source code encrypted using IONCube or anything like that? Looks like if that is the case you do not have the dynamic loaders.
-
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();
-
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
-
Only encrypt if the password is entered: if(strlen(trim($_POST['password']))) { $newPass = md5($_POST['password']); // update database } else { echo "Please enter a password"; }
-
Pass the $total and $quantity from my cart to the checkout page
JonnoTheDev replied to lebexpress's topic in PHP Coding Help
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']); -
eh? Are you a PHP developer? This simply means that the form data will be sent to /cgi-bin/write.plc when posted. write.plc must process the input
-
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!
-
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
-
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.
-
Check your mail log to see if the message is gone. Linux: cat /var/log/maillog
-
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);
-
Simple answer: yes If your are using joins on the products to ratings So your ratings table should have an index on productId // example ALTER TABLE ratings ADD INDEX (productId)
-
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.
-
If it is the correct session key name you are using $_SESSION['sessionKeyName'] then the only reason it would be blank is if it has no value. Print it to the screen before email as a test so: print $_SESSION['sessionKeyName']; exit(); Is it being destroyed anywhere? unset($_SESSION['sessionKeyName'])