将水平表格行转换为垂直表格 [英] Transform a horizontal table row into a vertical one

查看:107
本文介绍了将水平表格行转换为垂直表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CodeIgniter 2.1.0和MySQL。我想将水平数据行显示为垂直数据行。当我从数据库中获取单个行并回显它时,它看起来像

  ---------- ------------------------------ 
id |名称|地址|电子邮件|
----------------------------------------
1 | Foo | Bar | foo@bar.com |
----------------------------------------



我使用CodeIgniters表库来生成上面的表。而不是这样,我希望它像这样显示:

  ------ 
id:1
name:foo
地址:bar
电子邮件:foo@bar.com
-------------------



如何使用CodeIgniter 2.1.0?

解决方案

如果你有任何问题来实现我的上一个答案...这里是细节...
让我知道它是有用或不是吗?
谢谢。



/ * for controller * /



$ data ['user_data'] = $ this-> modle_name- > function_name;
modle_name =特定函数存在的模块名称。
function_name = function into the modle by which you get all the table value from mysql db。



然后在modle中写函数currectly并转到视图页面:可能像



/ * model * /

  function function_name(){
$ sql =select * from tablename where condition;
$ query = $ this-> db-> query($ sql);
return $ query-> result_array();
}

/ *视图* /

 <?php foreach($ user_data as $ data){? 
< tr>
<?php echo'ID:'。 ''?>
<?php echo($ data ['id']); >
<?php echo'Name:'。 ''?>
<?php echo($ data ['name']); >
<?php echo'Address:'。 ''?>
<?php echo($ data ['address']); >
<?php echo'E-mail:'。 ''?>
<?php echo($ data ['email']); >
< / tr>
<?php}?>


I am using CodeIgniter 2.1.0 and MySQL. I want to display a horizontal data row as a vertical one. When I fetch a single row from the database and echo it, it looks like

----------------------------------------
id    | name   | address | email       |
----------------------------------------
1     | Foo    | Bar     | foo@bar.com |
----------------------------------------

I have used CodeIgniters table library to generate the above table. instead of this, I want it show like this:

------
id : 1
name: foo
address : bar
email: foo@bar.com
-------------------

How do I do this with CodeIgniter 2.1.0?

解决方案

If you have any problem to implement my previous answer... Here is the details... Let me know is it useful or not? Thanks.

/* for controller */

$data['user_data'] = $this->modle_name->function_name; modle_name= your modle name where the specific function exists. function_name= function into the modle by which you get all the table value from mysql db.

then write the function currectly in modle and go to the view page:it may be like that

/* model */

function function_name(){
$sql = "select * from tablename where condition";
$query = $this->db->query($sql);
return $query->result_array();
}

/* for view */

<?php foreach ($user_data as $data) {?>
<tr>
 <?php echo 'ID:' . '  ' ?>
 <?php echo ($data['id']); ?>
 <?php echo 'Name:' . '  ' ?>
 <?php echo ($data['name']); ?>
 <?php echo 'Address:' . '  ' ?>
 <?php echo ($data['address']); ?>
 <?php echo 'E-mail:' . '  ' ?>
 <?php echo ($data['email']); ?>
</tr> 
<?php } ?>

这篇关于将水平表格行转换为垂直表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆