Jump to content

SQL Querry Help


TheJoey

Recommended Posts

Hi

 

From the very basics.

 

Firstly you need to connect to the database server, using a userid and password. Something like:-

 

$dbhost = 'www.mydb.com';

$dbuser = 'myUserid';

$dbpasswd = 'myPassword';

 

$conn = mysql_connect($dbhost,$dbuser,$dbpasswd);

 

Then select the actual database:-

 

$dbname = 'myDatabaseName';

mysql_select_db($dbname,$conn ) or die('Could not select database.'.mysql_error());

 

Then set up your piece of SQL.

 

$sql = "Select CodeID, Firstname, Lastname FROM GAMERS";

 

Execute the SQL, bringing back a result:-

 

$result = mysql_query($sql);

 

Then loop around bring back each row until you have processed them all / processed the ones you care about. This is executing mysql_fetch_assoc which grabs the next row from $result and puts it into an associative array which is assigned to $row.

 

while( $row = mysql_fetch_assoc($result) )

{

echo $row['CodeID']." ".$row['Firstname']." ".$row['Lastname'];

}

 

Hope those basics help.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.