Jump to content
xisto Community
Sign in to follow this  
iGuest

PHP FAQ--Read before posting!

Recommended Posts

Alright, here's my list of FAQs. Most of it I just copied from other threads in this forum.

 

General PHP Questions:

What is PHP? What is it used for? How do I use it?

PHP is the most common and most supported server-side scripting language. This means that the server executes your code and sends the result to your browser. It is usually used to generate dynamic content, such as you see in forums and content management systems. phpBB, IPB, vBulletin, PHPNuke, PostNuke, and practically every other system like them use PHP. To use it, you must first create a file named something.php. You can change the first part of the name, but not the extension. Then, you put your PHP code and/or HTML in that file. That's all!

 

What's the best way to learn PHP?

I would suggest buying a book and reading the whole thing, but that's expensive and time-consuming. I would specifically recommend PHP and MySQL Web Development, Third Edition. If you don't meet those requirements, here are a couple of good tutorial sites:

-They have a very basic tutorial and an excellent function reference.

W3Schools-Another basic tutorial.

PHPBuilder-They have a bunch of tutorials (in the articles tab), a bunch of code snippets, a forum, and a bunch of other stuff.

PHPFreaks-They have tutorials made by both themselves and their users, code snippets, fulls scripts, and a forum. Plus anything else I didn't mention.

PHP Resource Index-This site has a bunch of tutorials and PHP Classes.

 

 

MySQL PHP Questions:

How do I connect to MySQL with PHP?

First, make sure you have a database, user, and password. Then, you can sue the following code to connect to MySQL and select your database:

$db_handle = mysql_connect("localhost", "__username", "__password") or die("Error: Could not connect to MySQL!");$db_db = mysql_select_db("__database_name", $db_handle or die("Error: Could not select the database!");
You will need to edit this and set __username, __password, and__database_name to the username, password, and database name for you.

 

How do I execute a query in PHP?

Once you have connected to MySQL (see above), you can then execute mysql queries using the following statement:

$result = mysql_query("MYSQL QUERY HERE", $db_handle);
This will store the results of the query into $result. If there was an error, $result will be set to false. If there was no error, but no rows were returned, then $result will have no rows in it (Brilliant, eh?). If rows were returned, then $result will contain those rows.

 

Okay, I've executed my query, now what?

Now, you need to get those rows from the variable. There are several built-in functions which will help you with this:

First, mysql_num_rows will return the number of MySQL rows included in a result variable. Example:

$num_rows = mysql_num_rows($result);
Second, you can get those rows using the mysql_fetch_row or mysql_fetch_array functions. To see the differences, refer below. To use these functions, you will need to set up a loop which will access each row. You can use a for loop, with 1 as the initial condition and the result of mysql_num_rows as the ending condition. Example:
$num_rows = mysql_num_rows($result);for($i = 1; i < $num_rows; i++) {    $row = mysql_fetch_row($result);    //Do something with $row}

The other way, and for me the simpler way, is to use a while loop with the call to mysql_fetch_row included in the condition:

while( $row = mysql_fetch_row($result)) {    //Do something with $row}
What's the difference between mysql_fetch_row and mysql_fetch_array?

There's only one difference: the type of array which is returned. Otherwise, they function exactly the same. mysql_fetch_row will return an array containing the values of the current row as the values in the array. Thus, you will have to access them using their numerical indexes. Example:

$row[0];$row[1];...
mysql_fetch_array will return the array with either numerical indexes, as above, with the column name from MySQL as the keys, or with both. This depends upon the second argument. It has three possible values: MYSQL_NUM, MYSQL_ASSOC, and MYSQL_BOTH. Example:
$row = mysql_fetch_array($result, MYSQL_NUM); //Will return an array with numerical indexes.$row = mysql_fetch_array($result, MYSQL_ASSOC); //Will return an array with keys.$row = mysql_fetch_array($result, MYSQL_BOTH); //Will return an array with both numerical indexes and keys.

 

Obviously, there isn't much right now. That's because it takes alot of time to write alot. :) I'll add mroe as I get the time.

 

Links:

 

http://www.htmlgoodies.com/

QuoteMaster

http://forums.xisto.com/no_longer_exists/

Capitalize first word of every sentence

http://forums.xisto.com/no_longer_exists/

Quick Sort Function

http://forums.xisto.com/no_longer_exists/

Add commas to #'s

http://forums.xisto.com/no_longer_exists/

MyPHP Google PageRank

http://www.tapouillo.com/firefox_extension/sourcecode.txt

Dynamically Created PREV/NEXT Page Links

http://forums.xisto.com/no_longer_exists/

Complete recursive directory listing

http://forums.xisto.com/no_longer_exists/

CodeWalkers

https://codewalkers.com/

PHPBuilder.com - The Resource For PHP Developers

http://www.phpbuilder.com/

 

Please only respond to this post if it directly relates to this FAQ. Examples include suggestions, comments, and disagreements. DO NOT post questions about PHP in here. I'll just delete them, since I don't want this thread to get off-track. Thanks.

Share this post


Link to post
Share on other sites

Alright, here's my list of FAQs.  Most of it I just copied from other threads in this forum.

 

What is PHP? What is it used for? How do I use it?

PHP is the most common and msot supported


Dude, I've noticed a typo, change msot supported to most supported.

 

Delete this when sorted.

 

-Hazaa-

Share this post


Link to post
Share on other sites

Alright, here's my list of FAQs.  Most of it I just copied from other threads in this forum.

 

What is PHP? What is it used for? How do I use it?

PHP is the most common and msot supported


Dude, I've noticed a typo, change msot supported to most supported.

 

Delete this when sorted.

 

-Hazaa-


Nah I'll leave it there as an example of what a GOOD thing to post here is. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.