Open Source Development Tutorials | Newsletter Signup | About Us
Search  

Go Back   Open Source Tutorials Forum > Programming Languages > PHP Development
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-10-2003, 10:42 PM
TechieX TechieX is offline
Junior Member
 
Join Date: Nov 2003
Location: New York City
Posts: 12 TechieX is on a distinguished road
Post Looking for a Good start in PHP

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
Reply With Quote
  #2  
Old 11-10-2003, 10:47 PM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Default

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 or www.phpbuilders.com might be a good start.

Also 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).
__________________
md
Reply With Quote
  #3  
Old 11-10-2003, 10:59 PM
TechieX TechieX is offline
Junior Member
 
Join Date: Nov 2003
Location: New York City
Posts: 12 TechieX is on a distinguished road
Default

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 Code:
<?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.
Reply With Quote
  #4  
Old 11-10-2003, 11:17 PM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Default

PHP Code:
<?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.
__________________
md
Reply With Quote
  #5  
Old 11-11-2003, 02:49 PM
TechieX TechieX is offline
Junior Member
 
Join Date: Nov 2003
Location: New York City
Posts: 12 TechieX is on a distinguished road
Default

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 . Will let you know how it goes.
Reply With Quote
  #6  
Old 11-12-2003, 07:16 PM
TechieX TechieX is offline
Junior Member
 
Join Date: Nov 2003
Location: New York City
Posts: 12 TechieX is on a distinguished road
Arrow Here is the final result

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 Code:
<?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.
Reply With Quote
  #7  
Old 11-12-2003, 10:07 PM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Default

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
Reply With Quote
  #8  
Old 10-08-2006, 12:55 PM
md_doc md_doc is offline
ubergeek
 
Join Date: Oct 2003
Posts: 204 md_doc has disabled reputation
Default

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.
__________________
md
Reply With Quote
  #9  
Old 06-20-2007, 05:23 AM
Nabeel Nabeel is offline
Junior Member
 
Join Date: Jun 2007
Posts: 1 Nabeel is on a distinguished road
Default

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 | Wholesale Suppliers
Wholesale Canadian Directory | All UK Wholesalers
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



All times are GMT -5. The time now is 07:09 AM.


Powered by: vBulletin Version 3.0.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright 2004 - 2006 GrindingGears.com. All Rights Reserved.