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
https://forums.phpfreaks.com/topic/176778-sql-querry-help/#findComment-932376
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.