cwncool Posted January 27, 2007 Share Posted January 27, 2007 (Please keep in mind this is my first script I've written using MySQL)I have this code, trying to fetch the user's first name from the database and displaying it.[code]<?phpsession_start();if(!isset($_SESSION['username'])) {header("location:index.php");}include 'connect.php';$user = $_SESSION['username'];$name = mysql_query("SELECT first FROM users WHERE user='$user'");echo $name;?>[/code]Instead of echoing the name, it says Resource id #3. Can someone please tell me how I can echo the name please? Thanx! Link to comment https://forums.phpfreaks.com/topic/35976-solved-fetching-data-from-a-mysql-database/ Share on other sites More sharing options...
fert Posted January 27, 2007 Share Posted January 27, 2007 http://us2.php.net/manual/en/function.mysql-fetch-array.php Link to comment https://forums.phpfreaks.com/topic/35976-solved-fetching-data-from-a-mysql-database/#findComment-170615 Share on other sites More sharing options...
HoTDaWg Posted January 27, 2007 Share Posted January 27, 2007 [code]<?phpsession_start();if(!isset($_SESSION['username'])) {header("location:index.php");}include 'connect.php';$user = $_SESSION['username'];$name = mysql_query("SELECT first FROM users WHERE user='$user'");mysql_fetch_array($name);echo $name;?>[/code] Link to comment https://forums.phpfreaks.com/topic/35976-solved-fetching-data-from-a-mysql-database/#findComment-170620 Share on other sites More sharing options...
fert Posted January 27, 2007 Share Posted January 27, 2007 that code won't work Link to comment https://forums.phpfreaks.com/topic/35976-solved-fetching-data-from-a-mysql-database/#findComment-170625 Share on other sites More sharing options...
cwncool Posted January 27, 2007 Author Share Posted January 27, 2007 Yeah, that code doesn't work. Anyone else? Link to comment https://forums.phpfreaks.com/topic/35976-solved-fetching-data-from-a-mysql-database/#findComment-170633 Share on other sites More sharing options...
cwncool Posted January 27, 2007 Author Share Posted January 27, 2007 Yay, I got it to work with this...[code]<?phpsession_start();if(!isset($_SESSION['username'])) {header("location:index.php");}include 'connect.php';$user = $_SESSION['username'];$data = mysql_query("SELECT * FROM users WHERE user='$user'");$data = mysql_fetch_array($data); echo $data['first'];?>[/code] Link to comment https://forums.phpfreaks.com/topic/35976-solved-fetching-data-from-a-mysql-database/#findComment-170636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.