简体   繁体   English

用于从数据库获取数据的PHP代码,然后显示在表中

[英]PHP code for getting data from a db then display in a table

Am new to sql, mysql and php. 是sql,mysql和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. 我想要一个PHP脚本从学生资料中提取一些字段并打印在表格中。

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. 我想要一个SQL和PHP代码来提取“个人档案”列中的部分或全部数据。

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 上面的查询将获取用户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 或者对于特定用户,您可以再次使用Where子句...这样

 SELECT `username` FROM `users` WHERE `userid` = 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM