Jragon Posted July 22, 2010 Share Posted July 22, 2010 Hey guys, I was wondering how i could get a specific peace of information about the user? I know how to select the basics but i dont know how to get a specific peace of info Thanks Jraogn Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/ Share on other sites More sharing options...
timvdalen Posted July 22, 2010 Share Posted July 22, 2010 SELECT `columnname` FROM `users` WHERE `userid`='$id' or SELECT `columnname` FROM `users` WHERE `username`='$name' Whatever suits your needs. Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089473 Share on other sites More sharing options...
Jragon Posted July 22, 2010 Author Share Posted July 22, 2010 Thanks I was using it to get the salt of my password Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089475 Share on other sites More sharing options...
Jragon Posted July 22, 2010 Author Share Posted July 22, 2010 Ok so i have done that this is my function: <?php function getsalt($user){ include("connect.php"); $query = 'SELECT salt FROM user WHERE username = "$user"'; $salt = mysql_query($query); return $salt; } echo getsalt('rory'); ?> But all I'm getting is: Resource id #4 Thanks Jragon Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089477 Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 Hi, You should fetch your query: http://php.net/manual/en/function.mysql-fetch-array.php Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089478 Share on other sites More sharing options...
timvdalen Posted July 22, 2010 Share Posted July 22, 2010 You still need to make data from that. <?php function getsalt($user){ include("connect.php"); $query = 'SELECT `salt` FROM user WHERE username = "$user"'; $saltres = mysql_query($query); $saltdata = mysql_fetch_object($saltres); return $saltdata->salt; } echo getsalt('rory'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089479 Share on other sites More sharing options...
Jragon Posted July 22, 2010 Author Share Posted July 22, 2010 Ok so i tried your script and now i get nothing Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089483 Share on other sites More sharing options...
timvdalen Posted July 22, 2010 Share Posted July 22, 2010 Looks like it should work... What output does this give: <?php function getsalt($user){ include("connect.php"); $query = 'SELECT `salt` FROM user WHERE username = "$user"'; $saltres = mysql_query($query); $saltdata = mysql_fetch_object($saltres); print_r($saltdata); return $saltdata->salt; } echo getsalt('rory'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089485 Share on other sites More sharing options...
Jragon Posted July 22, 2010 Author Share Posted July 22, 2010 This is my dumb for the table -- phpMyAdmin SQL Dump -- version 3.2.4 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Jul 22, 2010 at 10:19 AM -- Server version: 5.1.41 -- PHP Version: 5.3.1 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `visualupload` -- -- -------------------------------------------------------- -- -- Table structure for table `user` -- CREATE TABLE IF NOT EXISTS `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(25) NOT NULL, `lastname` varchar(25) NOT NULL, `username` varchar(25) NOT NULL, `password` varchar(32) NOT NULL, `dob` date NOT NULL, `gender` varchar(1) NOT NULL, `salt` varchar(12) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `user` -- INSERT INTO `user` (`id`, `firstname`, `lastname`, `username`, `password`, `dob`, `gender`, `salt`) VALUES (1, 'Rory', 'Anderson', 'rory', 'hello', '2010-07-07', 'm', 'akldflasjkdf'); Nothing still Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089486 Share on other sites More sharing options...
timvdalen Posted July 22, 2010 Share Posted July 22, 2010 $query = "SELECT `salt` FROM `user` WHERE `username` = '$user'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $data = mysql_fetch_object($result); print_r($data); $salt = $data->salt'; print $salt; Well, try this Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089488 Share on other sites More sharing options...
Jragon Posted July 22, 2010 Author Share Posted July 22, 2010 its half working now what i get stdClass Object ( [salt] => akldflasjkdf ) akldflasjkdf Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089489 Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 Use while... $query = "SELECT `salt` FROM `user` WHERE `username` = '$user'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); while ($data = mysql_fetch_object($result)) { echo $data->salt; } Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089493 Share on other sites More sharing options...
Jragon Posted July 22, 2010 Author Share Posted July 22, 2010 Thanks its all working now! Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089496 Share on other sites More sharing options...
timvdalen Posted July 22, 2010 Share Posted July 22, 2010 its half working now what i get stdClass Object ( [salt] => akldflasjkdf ) akldflasjkdf This is not half working, this is already working. You first print_r the object and then print salt. They were both printed, if you leave out the print statements and insert return $salt it should work, I see point in using a loop here, as you only want one result. (if you are going to use a loop, make sure you include LIMIT 1 in your query) Quote Link to comment https://forums.phpfreaks.com/topic/208521-how-to-select-a-peace-of-information-from-mysql/#findComment-1089509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.