dongzhi4690 2012-11-18 12:44
浏览 38
已采纳

laravel视图中的Foreach和Mysql

I have got Laravel to work for doing simple HTML pages, routing worked, as defined at this question of mine but I am not sure how to get MySQL and PDO working in a view.

I can get 'traditional' Hello world PHP/MySQL queries working in a view, but am not quite sure how to do this with Laravel's framework.

I read through the documentation but couldn't find anything on how to do this - anyone got any ideas?

Currently I have a basic page, but want to get a simple foreach query working, echoing data from this table:

testingdb Tablename: test1

name VARCHAR (255)
town VARCHAR (255)
biography TEXT

How would I get this to work without using the traditional PHP/MySQL methods that are normally mentioned in tutorials and using pdo instead (source, nettuts, why you should use PDO article)?

Is there something I need to do, create a controller etc?

  • 写回答

2条回答 默认 最新

  • dozan0001 2012-11-18 12:51
    关注

    you can find the answer in the documents here http://laravel.com/docs/database/eloquent

    to show you an example : 1) first form your model ( eg . test1) 2) make a database table connection and foreach like here:

    foreach (test1::all() as $test)
    {
         echo $test->name;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条