I have used the following query on a MySQL table;
$sql = "SELECT FirstName, LastName FROM user;";
mysql_query($sql);
This will return some values from the FirstName and LastName columns of the table. How do i now use this returned information.
E.g
Hello 'FirstName' your last name is 'LastName'
PHP and SQL queries...
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<?php
$sql = "SELECT FirstName, LastName FROM user;";
$result = mysql_query($sql);
//loop through each row
while ($row = mysql_fetch_assoc($result))
{
echo 'your firstname is '. $row['FirstName'] .' and your lastname is '. $row['LastName'];
}
?>-
richcoleuk
- Forum Newbie
- Posts: 24
- Joined: Fri Nov 05, 2004 1:33 pm
okay thanks for that. I have a variable called $uname that holds the username of the user. I want to use this to add to the previous query so that it will select just the user WHERE username = '$uname'
This doesn't work:
$sql = "SELECT FirstName FROM user WHERE UserName = '" + $uname + "';
i get the error:
Parse error: parse error in /home/cr202/public_html/success.php on line 33
This doesn't work:
$sql = "SELECT FirstName FROM user WHERE UserName = '" + $uname + "';
i get the error:
Parse error: parse error in /home/cr202/public_html/success.php on line 33
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
$sql = "SELECT FirstName FROM user WHERE UserName = '".$uname."'";- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: