0

我正在尝试使用 php 和 mysql 从我的数据库中检索 fata。我已经设法从表格的第一行获取数据,但我似乎无法找到让它到达第二行的方法,依此类推。

我的数据库是这样的:(
表中的第一行)

id [int] -> 7  
user_id [int] -> 23  
user_task_id [int] -> 4  
description [varchar] -> Text Text Text Text Text  
date_creation [timestamp] -> 2013-07-17  
date_end [datetime] -> 0000-00-00  
date_conclusion [datetime] -> 0000-00-00  
status_id [int] -> 3  
notes [text] -> Text Text Text Text Text Text  
categoria_id [int] -> 12  
entity_id [int] -> 17

(表中的第二行)

id [int] -> 8  
user_id [int] -> 6  
user_task_id [int] -> 9  
description [varchar] -> Text Text Text Text Text  
date_creation [timestamp] -> 2013-07-20  
date_end [datetime] -> 0000-00-00  
date_conclusion [datetime] -> 0000-00-00  
status_id [int] -> 4  
notes [text] -> Text Text Text Text Text Text  
categoria_id [int] -> 18  
entity_id [int] -> 10

继承人的代码:

<?php
function get_all_tasks() {
        global $connection;
        $query = "SELECT * FROM tarefas;";
        $tasks_set = mysql_query($query, $connection);
        confirm_query($tasks_set);
        return $tasks_set;
}
?>


<table class="table_content">
                    <thead>
                        <tr>
                            <td>ID</td>
                            <td>User Task</td>
                            <td>Description</td>
                            <td>Entity ID</td>
                            <td>Date End</td>
                            <td>Status</td>
                            <td>Actions</td>
                        </tr>
                    </thead>
                    <?php 
                    ?>
                    <tbody>
                        <tr>
                        <?php 
                            if($task_data = mysql_fetch_array(get_all_tasks())){
                            foreach ($task_data as $task) { ?>
                          <tr>
                            <td><?php echo $task['id'] ?></td>
                            <td><?php echo $task['user_task_id'] ?></td>
                            <td><?php echo $task['description'] ?></td>
                            <td><?php echo $task['entity_id'] ?></td>
                            <td><?php echo $task['date_end'] ?></td>
                            <td><?php echo $task['status_id'] ?></td>
                            <td><?php echo "" ?></td>
                          </tr>
                            <?php }}
                        ?>
                    </tbody>
                </table>
4

4 回答 4

0

尝试这个

    <?php
  function get_all_tasks() {
    global $connection;
    $query = "SELECT * FROM tarefas;";
    $tasks_set = mysql_query($query, $connection);
    confirm_query($tasks_set);
      foreach ($task_data as $task) { ?>
                      <tr>
                        <td><?php echo $task['id'] ?></td>
                        <td><?php echo $task['user_task_id'] ?></td>
                        <td><?php echo $task['description'] ?></td>
                        <td><?php echo $task['entity_id'] ?></td>
                        <td><?php echo $task['date_end'] ?></td>
                        <td><?php echo $task['status_id'] ?></td>
                        <td><?php echo "" ?></td>
                      </tr>
                        <?php }

}
 ?>


  <table class="table_content">
                <thead>
                    <tr>
                        <td>ID</td>
                        <td>User Task</td>
                        <td>Description</td>
                        <td>Entity ID</td>
                        <td>Date End</td>
                        <td>Status</td>
                        <td>Actions</td>
                    </tr>
                </thead>
                <?php 
                ?>
                <tbody>
                    <tr>
                    <?php 
                       echo get_all_tasks() ;
                    ?>
                </tbody>
            </table>

注意:不推荐使用 mysql_* 最好使用 mysqli 或 PDO

于 2013-07-20T14:50:52.907 回答
0

将调用移到 while 循环之外的函数。并编写如下代码

<?php 
   $data = get_all_tasks();
   while (($task = mysql_fetch_array($data))) {
                <tr>
                            <td><?php echo $task['id'] ?></td>
                            <td><?php echo $task['user_task_id'] ?></td>
                            <td><?php echo $task['description'] ?></td>
                            <td><?php echo $task['entity_id'] ?></td>
                            <td><?php echo $task['date_end'] ?></td>
                            <td><?php echo $task['status_id'] ?></td>
                            <td><?php echo ""
于 2013-07-20T14:52:40.517 回答
0

尝试使用这个:

而 ($task = mysql_fetch_array(get_all_tasks()) { 你的 html }

请记住,不推荐使用 mysql_*,最好使用 mysqli 或 PDO。

于 2013-07-20T14:50:32.677 回答
0

只需使用以下内容更新您的get_all_task功能:

<?php
function get_all_tasks() {
        global $connection;
        $query = "SELECT * FROM tarefas;";
        $tasks_set1 = mysql_query($query, $connection);
       while ($task_set = mysql_fetch_array($tasks_set1, MYSQL_ASSOC))
        return $tasks_set;
}
?>
于 2013-07-20T15:01:46.357 回答