Am new to sql, mysql and php. However, am learning. I have a database that collects students admission records. I want a PHP script to extract some fields from the students profile and print in a table.
Below ia sample of the database structure and an entry.
Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`salt` text,
`userid` int(11) NOT NULL AUTO_INCREMENT,
`username` text,
`password` text,
`email` text,
`register_date` int(11) DEFAULT NULL,
`active` tinyint(4) DEFAULT NULL,
`reg_salt` text,
`level` int(11) DEFAULT NULL,
`ip` text,
`profile` text,
PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9653 ;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`salt`, `userid`, `username`, `password`, `email`, `register_date`, `active`, `reg_salt`, `level`, `ip`, `profile`)
Within the 'Profile' column are data subsets that the user or admin enters via the website in a XML defined table. An example below
VALUES
('fc61f', 1, 'Admin', 'mutolo', 'smutolo@gmail.com', 1200247562, 1, 'e14973fc61f2bf249c540eb14b8525', 1, 'a:7:{s:14:"82.145.221.205";i:1;s:13:"82.145.221.54";i:1;s:14:"105.166.190.60";i:1;s:15:"197.181.203.204";i:1;s:14:"197.178.16.134";i:11;s:14:"105.166.241.43";i:1;s:15:"197.178.252.241";i:1;}', 'a:21:{s:10:"first_name";s:5:"Nzisa";s:9:"last_name";s:4:"Muli";s:6:"Gender";s:4:"Male";s:6:"County";s:0:"";s:8:"District";s:0:"";s:8:"Location";s:0:"";s:5:"Chief";s:0:"";s:6:"Orphan";s:25:"Yes Both Parents Deceased";s:6:"Parent";s:0:"";s:9:"Emergency";s:0:"";s:7:"Primary";s:0:"";s:4:"KCPE";s:0:"";s:20:"A_Little_Information";s:29:"I am the school administrator";s:9:"Notify_Me";s:1:"1";s:11:"alumni_year";s:4:"2010";s:7:"Picture";N;s:17:"alumni_include_me";s:1:"1";s:6:"Stream";s:0:"";s:9:"Admission";s:0:"";s:5:"House";s:0:"";s:8:"user_pic";s:5:"1.JPG";}'),
('4a1b6', 9641, 'bb', 'c80d5f83dbf874c4caebedfde385e1af', 'smutolo@gmail.com', 1389444756, 0, 'a2becf9eff6dbcde14ef8c1274a1b6', 10, NULL, 'a:21:
<====profile data starts here====>
{s:10:"first_name";s:6:"Stella";s:9:"last_name";s:4:"King";s:6:"Gender";s:6:"Female";s:6:"County";s:5:"Kitui";s:8:"District";s:8:"Katulani";s:8:"Location";s:8:"Kathungi";s:5:"Chief";s:13:"Mr. Kasasaana";s:6:"Orphan";s:19:"Yes Father Deceased";s:6:"Parent";s:17:"Mr. Mutua Stephen";s:9:"Emergency";s:27:"Mr. Mutua Stephen-074321234";s:7:"Primary";s:7:"Kakuswi";s:4:"KCPE";s:3:"234";s:20:"A_Little_Information";s:39:"Am good in soccer\r\n\r\nAm allergic to oil";s:9:"Notify_Me";s:1:"1";s:11:"alumni_year";s:4:"2010";s:7:"Picture";N;s:17:"alumni_include_me";s:1:"1";s:6:"Stream";s:7:"1 South";s:9:"Admission";s:4:"3423";s:5:"House";s:5:"Nyayo";s:8:"user_pic";s:8:"9641.JPG";}')
I want a SQL and PHP code to extract some or all of the data in the column Profile.
Hope am clear. Thanks alot
To select all the results from DB you can do
SELECT * FROM `users`
This will fetch everything (All Users and ALL Columns).
To fetch a specific user you can do
SELECT * FROM `users` WHERE `userid` = 1
the above query will fetch a user with user id 1
Both of the above queries will fetch all the columns. In order to get a specific column you can do
SELECT `username` FROM `users`
it will give you all user names
Or for a specific user, you can again use the Where clause...So it will be
SELECT `username` FROM `users` WHERE `userid` = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.