Looking for a Good start in PHP


Read With Formatting | Free Open Source Tutorials Account

PHP Development
Thread: Looking for a Good start in PHP


TechieX
I have been doing Webdev, for a while. although I kinda got more into the Graphics end of things I dabbled in Cold Fusion, Light ASP, and now Im interested in learning PHP. Alomg with others.

What do you recommend for a newbie that will give him the basic foundation? I have a PHP book from BN and it ok I also got some info online, but always looking for more. Any suggestions would be greatly appreciated. Thanks

md_doc
Is there anything specific you are looking for or something specific you are looking to do? If you are looking for just general php howtos then a site like www.webmonkey.com (http://www.webmonkey.com) or www.phpbuilders.com (http://www.phpbuilders.com) might be a good start.

Also www.opensourcetutorials.com (http://www.opensourcetutorials.com) has a bunch of php tutorials and articles covering the basics. If you have specific questions be it Object Oriented designt with PHP or the best way to do x or y please feel free to ask though as there are a few great php programmers here (even though we are only like 10 members large right now we do have quality members).

TechieX
Thanks md_doc yeah there is, and I hope you can help. all I want to do right now is query a MYSQL DB. I want to do a SELECT and have it show in the webpage. BUT I just want that one record. all the examples I see have an array and well... gets me confused.

Here's an example of what I have so far:

<?php

// Setting the connection variables
$username="username";
$password="password";
$database="mydb";

//Connecting to the database
mysql_connect("localhost", "$username", "$password");

//Selecting the Database
@mysql_select_db($database)or die("Unable to select database");

// SQL Select Statement
$result = @mysql_query("SELECT * FROM table where id=2");


// Output the reults to webpage

Now all I want is the one recored liisted "id=2" ?

?>


I tried echo and print result, but it does not work. I know I can simply copy the array code, but I want to understand what Im doing, and not just throw code in place.

All in all Im looking for a simple PHP/MYSQL select statement to pull a record onto a webpage. Thanks for any suggestions.

md_doc
<?php

// Setting the connection variables
$username="username";
$password="password";
$database="mydb";

//Connecting to the database
mysql_connect("localhost", "$username", "$password");

//Selecting the Database
@mysql_select_db($database)or die("Unable to select database");

// SQL Select Statement
$result = @mysql_query("SELECT * FROM table where id=2");

// Output the reults to webpage
print $result[0];

?>


By doing a print $result[0] you actually print the first index of the array or in this case you will print out the first element in the record. If the first one is say FirstName then the first name field will be printed out.

The index of $result will go from 0 to the number of columns in the table minus 1.

TechieX
Thanks md_doc

I will give this is shot when I get in this evening. Along with the many other things I need to do :D . Will let you know how it goes.

TechieX
Well after trying your update I still had some trouble. but I decided to sit back and readup on a couple of things, and well here is what I did, and it works perfectly. Thank you.


<?php

// Setting the connection variables
$username="username";
$password="password";
$database="dbname";

//Connecting to the database
$db = mysql_connect("localhost", "$username", "$password");

//Selecting the Database
mysql_select_db("$database",$db)or die("Unable to select database");

// SQL Select Statement
$sql_result = mysql_query("SELECT col FROM Table WHERE ID=1",$db);

// Output the results to the page.
$rs = mysql_fetch_row($sql_result);
echo $rs[0];

?>


The above worked like a charm. ;)

md_doc
Nice job putting the $db in your mysql_select. Most people do not put that in there but you really should if you ever expect that you will end up using more than one database connection on a page.

I have tried to modify many pieces of code where it was not used and my modification required I connect to a different database server so it made things interesting.

md_doc
Please submit your questions to the forum. The purpose of the forum is for a user to post a quesiton and the community to help that user. The information is then kept in the forum so that other users can benefit from it as well.

Nabeel
Hi, This post is very informative, however I would like some specific information. If someone can help me then please send me a private message. Best Regards,

Pakistan Property (http://www.zameen.com) | Wholesale Suppliers (http://www.dailytrader.com)
Wholesale Canadian Directory (http://www.wholesale-canada.com) | All UK Wholesalers (http://www.uk-wholesaler.co.uk)