douhuang1973 2012-08-23 19:44
浏览 47
已采纳

使用PHP / MySQL和JavaScript填充多个HTML Div

I've noticed several threads on here and through Google searches on how to do this, but I need something a little more specific to my needs in order to execute it as I am pretty new to PHP. Hopefully someone can help.

I have a page with 5 Divs (lets just call them 1-5). I have a MYSQL database named 'Users' with columns 'ID' (primary key), 'Member', 'Review' and 'location'.

I would like to randomly populate each Div with rows from this DB and show information from the above mentioned columns.

Can anyone give me guidance on where to begin, or possibly give me sample code that meets the above criteria?

Thanks so much for any help.

  • 写回答

1条回答 默认 最新

  • douhu2131 2012-08-23 20:13
    关注

    Here is a general answer:

    1) in PHP establish a connection to you database. something like this:

    $connection = mysql_connect($host,$username,$password);
    

    2) query the database:

    mysql_select_db($schema, $connection);
    
    $result = mysql_query("Put your sql query here...");
    

    3) loop over the results and echo them to the screen,

    while($row = mysql_fetch_array($result))
    {
        echo $row['mysql_column_name_here'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改