News:
 
Welcome, Guest. Please login or register.
Did you miss your activation email?


+  Webmaster Key Forums
|-+  Webmaster Corner
| |-+  Site Design and Web Authoring
| | |-+  Coding Talk
| | | |-+  Simple guide to PHP coding
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 [2]  All Go Down Send this topic Print
Author Topic: Simple guide to PHP coding  (Read 14160 times)
Andy
Key Master
Veteran
*****
Posts: 5 598



« Reply #15 on: March 26, 2008, 09:54:30 AM »

Quick tip for debugging MySQL database problems:

If you get an invalid result resource error, it means that your query is malformed. It is nothing to do with zero rows of data being found.

In the PHP documentation you will see verbose MySQL query examples that do too much error checking in my opinion. As long as your code produces valid queries, you should never see the invalid resource error. And if you do see these errors, so will your users, even if you report the errors to the browser.

So all you need to check for is number of rows returned after a "select" query and number of affected rows after other queries if you need to know.

p.s. I always form my query in a string before executing the mysql_query() function since it is very easy to insert an echo or die to view the offending query when de-bugging your code e.g.

Code:
<?php
$q "SELECT `name` FROM `categories` WHERE `id`='$cat'";
                echo 
"Q: $q "// Debug it
                
die("Q: $q "); // Or break at this point
connect_to_db();
$r mysql_query($q);
?>


Once the problem is resolved, I remove any debug code like this.
Report to moderator   Logged
Andy
Key Master
Veteran
*****
Posts: 5 598



« Reply #16 on: March 27, 2008, 08:33:17 AM »

One aspect of coding SQL queries that I avoided until now was how to combine 2 tables into one query. The standard MySql documentation is difficult to understand I think.

The easy way to understand how to do it is explained at this web site:
http://www.halfgaar.net/sql-joins-are-easy

 
Report to moderator   Logged
Andy
Key Master
Veteran
*****
Posts: 5 598



« Reply #17 on: June 18, 2008, 04:03:51 PM »

To get started in PHP you could try this simple code to display the current year in your web template:

Code:
<?php echo date("Y"); ?>

This is useful next to your copyright symbol.
Report to moderator   Logged
donecweb
Key Master
Veteran
*****
Posts: 1 173


DonecWeb


« Reply #18 on: June 19, 2008, 02:01:55 AM »

To get started in PHP you could try this simple code to display the current year in your web template:

Code:
<?php echo date("Y"); ?>

This is useful next to your copyright symbol.
Wouldn't you want to use the first date you copyrighted it?
Report to moderator   Logged

DonEc Web

Links and accurate information provide the best answer, while garbage in provides garbage out.
Andy
Key Master
Veteran
*****
Posts: 5 598



« Reply #19 on: June 19, 2008, 09:47:29 AM »

Quote
Wouldn't you want to use the first date you copyrighted it?
You can show a range of years from the 1st year to the current year. That seems to be a common practice.
Report to moderator   Logged
Pages: 1 [2]  All Go Up Send this topic Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!