|
| Web Hosting Deals | Holiday Logo Design | Webcam Chat | Website Header Templates | Register domain | Search Engine Optimisation | Web Hosting |
|
|||||||
| Programming / Scripting / Coding Got a question about : PHP / Perl / Java / JavaScript / CGI Scripts / JavaScript coding. Ask here! We'll get you the answers ! |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
||||
|
Ok, so by your post i am guessing your using such a tool as command line SQL?
Or your going to use a programming language.. Or you want to literally know how to execute an SQL query. I will awnser the last one first. Say you wanted to get all of the information from the table called talk-mania So in any language that deals with SQL you would have (somewhere in the code) Code:
SELECT * FROM talk-mania One is the baisic command line that you get with any SQL installation let it be mysql or even msSQL you will allways get a command line with it. But! Lets say your on a shared host, then you don't have a command line *OH NOES!!!* Then what you need is an SQL tool, now the most popular tool for such things (its most likey you will have heard of it) is callled PHP MY ADMIN this is a script supprisingly enough written in PHP, that allows you to administer any number of databases, on any number of systems, from one simple tool. This also has a SQL command line tool, built in ![]() Check it out @ www.phpmyadmin.net BUT! Lets say thats not what your after, and lets say you have PHP my admin installed and you can use it, but you want somthing for the end user to see. SO! For this you need a programming language. Now the most popular for SQL querys is PHP, SQL is built in, you don't have to add anything at all.. Well lets take the same example, that you wanted to select everything in the table called talk-mania. Now if your using PHP, then your going to need to define a few things first. PHP Code:
But i will briefly go through this line by line for you. mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); OK, so we are using the function mysql_connect and now we are going to declare a few things. "localhost" - This is the ip address of where the server which contains the database is. If its on the same server, then you use localhost. "admin" - this is the username you connect to the database with. "1admin" - and this is the password. or die(mysql_error()) This is a great little thing, lets you display the reason why it failed, bloody usefull if your testing. mysql_select_db("test") or die(mysql_error()); so we are using the function mysql_select_db which supprisingly enough means "in mysql selcect the database that i am going to define." "test" this is the name of the database your trying to connect too. $result = mysql_query("SELECT * FROM example") So this is the meat really. mysql_query. This is what your after i think, this is the PHP command to query a database, you can put any valid command in between these to speach marks and it will query it. $row = mysql_fetch_array( $result ); Now this is another fantastic thing. mysql_fetch_array is literally fetching the data, and making it an array (array meaning "an orderly arrangement") so the contents of $result which in this case is "mysql_query("SELECT * FROM example")" its going to place into a nice order. echo "Name: ".$row['name']; echo " Age: ".$row['age']; OK! So we are saying echo the following: Name: (the contents of the variable $row) (within the row called 'name') So yeah! I hope that helped.. And if it hasent awnsered your question. Then next time, be more specific :P Cheers and hope you learned somthing! Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. |
|
||||
|
Just for me, was it the PHP example you were looking for?
Cheers Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|