在 div 标签中从 MySQL 接收数据 [英] Receive data from MySQL in a div tag

查看:29
本文介绍了在 div 标签中从 MySQL 接收数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码现在一团糟,但我只是在尝试一些东西.但我有以下页面:

索引:

<头><link rel="stylesheet" type="text/css" href="css\placing.css"><title>数字</title><身体><div class="topbar">顺丰

<div class="talraekke"><p>测试</p>

<div class="内容"><p>输入数字</p><form action="action.php" method="post" ><input type="value" name="numbervalue"><输入类型=提交"></表单>

</html><?php包括'action.php';?>

还有我的 actionpage.php:

从数据库中,我收到了一些我在表格中输入的数字.但我希望这些数字在 :

<p>测试</p>

但是我如何在我的 div 标签中调用这些数据?

最好的问候疯子

解决方案

只需替换代码中的以下部分即可.

echo "

";while($row = mysql_fetch_array($rs)) {echo "<p>".$row['numbers'] ."</p><br/>";}echo "</div>";

My code is a mess right now, but I am just trying out some things. But I have the following pages:

index:

<html>

<head>
    <link rel="stylesheet" type="text/css" href="css\placing.css">
    <title>Numbers</title>
</head>

<body>
    <div class="topbar">
        sf
    </div>
    <div class="talraekke">
        <p>test</p>
    </div>
    <div class="content">
        <p>Enter The Number</p>
        <form action="action.php" method="post" >
            <input type="value" name="numbervalue">
            <input type="submit">
        </form>
    </div>

</body>
</html>

<?php 
include 'action.php';
?>

And my actionpage.php:

<?php

$username = "root";
$password = "root";
$hostname = "127.0.0.1:3306"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
//echo "<br><br>Connected to MySQL<br><br>";

//select a database to work with
$selected = mysql_select_db("roulette_db",$dbhandle) 
  or die("Could not select any database");


echo "<h1>Hello " . $_POST["numbervalue"] . "</h1>";

    // Insert To Database
$strSQL = "INSERT INTO numbertable(numbers) VALUES('" . $_POST["numbervalue"] . "')";
// The SQL statement is executed 
    mysql_query($strSQL) or die (mysql_error());

    // SQL query
    $strSQL = "SELECT * FROM numbertable";

    // Execute the query (the recordset $rs contains the result)
    $rs = mysql_query($strSQL);

    // Loop the recordset $rs
    // Each row will be made into an array ($row) using mysql_fetch_array
    while($row = mysql_fetch_array($rs)) {

       // Write the value of the column FirstName (which is now in the array $row)
      echo $row['numbers'] . "<br />";
}

  // The SQL statement is executed 
    mysql_query($strSQL) or die (mysql_error());

    // Close the database connection
    mysql_close();
?>

From the database I recive some numbers that I have put in my form. But I would like that those numbers are inside the :

<div class="talraekke">
    <p>test</p>
</div>

But how can I call that data in my div tag?

Best Regards Mads

解决方案

Just replace the below section from your code.

echo "<div class='talraekke'>";
while($row = mysql_fetch_array($rs)) {
    echo "<p>".$row['numbers'] . "</p><br />";
}
echo "</div>";

这篇关于在 div 标签中从 MySQL 接收数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆