query retuerning资源ID#10

时间:2015-10-05 12:55:17

标签: php mysql

我想显示具有特定列名称的行数。当我执行查询时,没有显示错误,但给出的输出只是资源ID#10。我是php和mysql领域的初学者。谁能帮我吗 ? 我尝试了下面给出的代码

    $sql ="SELECT column1,column2 FROM table1 WHERE user_id='name' GROUP BY time_stamp";    
    $result = mysql_query($sql);
    $count=1;
    while($row = mysql_fetch_array($result)) {
        echo "<form action=table2.php method=GET>";
        echo"<tr>";
        $row_no="SELECT COUNT(time_stamp) FROM table1";
        $row_num = mysql_query($row_no);



        echo "<td>" .$count. "</td>";
        echo "<td>" .$row["column1"]. "</td>";
        echo "<td>" .$row["column2"]. "</td>";
        echo "<td>" .$row_num. "</td>";
        echo "<td>" ."<input class=btn type=submit value=Delete". "></td>";

        echo"</tr>";
        echo "</form>";
        $count=$count+1;
    }

2 个答案:

答案 0 :(得分:0)

您需要为执行的第二个查询获取数组,然后使用它的echo

$sql ="SELECT column1,column2 FROM table1 WHERE user_id='name' GROUP BY time_stamp";    
$result = mysql_query($sql);
$count=1;
while($row = mysql_fetch_array($result)) {
    echo "<form action=table2.php method=GET>";
    echo"<tr>";
    $row_no="SELECT COUNT(time_stamp) AS cnt FROM table1";
    $row_num = mysql_query($row_no);
    $row_num_res = mysql_fetch_array($row_num);

    echo "<td>" .$count. "</td>";
    echo "<td>" .$row["column1"]. "</td>";
    echo "<td>" .$row["column2"]. "</td>";
    echo "<td>" .$row_num_res["cnt"]. "</td>";
    echo "<td>" ."<input class=btn type=submit value=Delete". "></td>";

    echo"</tr>";
    echo "</form>";
    $count=$count+1;
}

答案 1 :(得分:0)

您需要在第二个查询中获取计数。您可以使用mysql_fetch_row

执行此操作
$sql ="SELECT column1,column2 FROM table1 WHERE user_id='name' GROUP BY time_stamp";    
    $result = mysql_query($sql);
    $count=1;
    while($row = mysql_fetch_array($result)) 
    {
        echo "<form action=table2.php method=GET>";
        echo"<tr>";
        $row_no= mysql_query("SELECT COUNT(time_stamp) as count FROM table1");
        $row_num = mysql_fetch_row($row_no);
        echo "<td>" .$row_num[0]. "</td>";
        echo "<td>" .$row["column1"]. "</td>";
        echo "<td>" .$row["column2"]. "</td>";
        echo "<td>" .$row_num. "</td>";
        echo "<td>" ."<input class=btn type=submit value=Delete". "></td>";
        echo"</tr>";
        echo "</form>";
        $count=$count+1; 
    } 

注意:不要使用mysql_*不推荐使用这些功能。请改用mysqli_*PDO