I want to display the number of the rows with a specific column name . When i am executing the query, no error is showing but the output given is just Resource id #10. I am a beginner in php and mysql field . Can anyone help me out ? I tried the given below code
$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;
}
You need to fetch the array for the second query you execute and then use it's column for 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;
}
You need to fetch the count in the second query. You can do it using 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;
}
Note: Do not use mysql_*
These functions are deprecated. Use mysqli_*
or PDO
instead.