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 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序