douji6896 2015-12-07 19:10
浏览 69
已采纳

以div标签从MySQL接收数据

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

  • 写回答

1条回答 默认 最新

  • dongpang1232 2015-12-08 11:05
    关注

    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>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分