Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> PHP FAQ--Read before posting!
God
post Jan 27 2005, 11:59 PM
Post #1





Guests






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:
[list]-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.
[list]

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:
CODE
$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:
CODE
$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:
CODE
$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:
CODE
$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:
CODE
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:
CODE
$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:
CODE
$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. biggrin.gif I'll add mroe as I get the time.

Links:
[list]
http://www.wdvl.com/Authoring/Languages/PHP/Date_Time/
QuoteMaster
http://www.phpbuilder.com/snippet/detail.p...=snippet&id=177
Capitalize first word of every sentence
http://www.phpbuilder.com/snippet/detail.p...snippet&id=1037
Quick Sort Function
http://www.phpbuilder.com/snippet/detail.p...e=snippet&id=10
Add commas to #'s
http://www.phpbuilder.com/snippet/detail.p...=snippet&id=542
MyPHP Google PageRank
http://www.tapouillo.com/firefox_extension.../sourcecode.txt
Dynamically Created PREV/NEXT Page Links
http://www.phpbuilder.com/snippet/detail.p...=snippet&id=862
Complete recursive directory listing
http://www.phpbuilder.com/snippet/detail.p...=snippet&id=249
CodeWalkers
http://codewalkers.com/
PHPBuilder.com - The Resource For PHP Developers
http://www.phpbuilder.com/[list]

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.
Go to the top of the page
 
+Quote Post
Hazaa
post Jan 28 2005, 12:03 AM
Post #2





Guests






QUOTE
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-
Go to the top of the page
 
+Quote Post
God
post Jan 28 2005, 12:07 AM
Post #3





Guests






QUOTE
QUOTE
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. biggrin.gif
Go to the top of the page
 
+Quote Post
y04chs067
post Feb 12 2005, 11:46 AM
Post #4





Guests






LOL.If anyone wants some ebooks on PHP/MySQL,PM me..I can give you some..
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Can You Read In Your Dreams?(26)
  2. Google Sketchup - Introduction(2)
  3. Last Book You Read?(203)
  4. Welcome All New Registered Users Of Trap17(0)
  5. Mac To Read Microsoft Word(3)
  6. **** Read Before You Post! ****(48)
  7. Read This Before Applying For Hosting!(58)
  8. Tracking My Stolen Laptop(8)
  9. Eragon(54)
  10. Who Is The Best Writer Did You Ever Read And His Or Her Book(11)
  11. Sendearnings.com(17)
  12. About Posting Form(2)
  13. Im Making A Mmorpg >>(14)
  14. Trap17 Gets Supernatural: Topics Disappear!(7)
  15. Read This At Any Cost Before Posting Here(8)
  1. Read-only Folders In Xp(13)
  2. Living Everyday Happily And Meaningfully(5)
  3. Dvd Drive Problem(10)
  4. Compatibility/major Question(5)
  5. Beside novel or friction, what do you read?(5)
  6. Can't Read E-mail(0)
  7. Read File (.txt) On Another Website Using Jsp?(3)
  8. Free Web Hosting Application [screened] [approved](6)
  9. Free Wap! Omg!(4)
  10. Hackers Hijack A Half-million Sites: Phpbb Forum Users Must Read(8)
  11. Cpanel Raw Acess Log(1)
  12. Topic Not Posting [resolved](3)
  13. Ftp Access Has Stopped Working All Of A Sudden [resolved](5)
  14. Have You Read The Rules?(27)
  15. The Great Gatsby And The American Dream(4)


 



- Lo-Fi Version Time is now: 13th October 2008 - 10:33 AM