0

I want to show users the number of records on the database.
I have this on my html page:

How many ships are listed ?
<form action="rowcount.php" method="post" target="_blank"><input type="submit" value="Answer here" /> </form>
with about 8,000 names.

and this :

<?php
require_once 'dbconnect.php';

$query="SELECT COUNT(name1) FROM allnames";

$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
while($row=mysql_fetch_array($result))
{
echo "<table border='1'  width='75' height='20'/>";
echo "<tr><td>";
echo "<h1>".$row['COUNT(name1)']."</h1>";
echo "</td></tr>";
echo "</table>";
echo "with some 8,000 different names";
}
?>

I want to position the result just after the submit button within the accompanying text.
Any ideas, please ?

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
0

It sounds as though you want to submit a form using the submit button which then refreshes the page to show text below the form itself. Right?

A trivial solution would be:

<?php
if(isset($_POST['sendme'])){
  $ans = "";
  require_once 'dbconnect.php';
  $query="SELECT COUNT(name1) AS n1 FROM allnames";
  
  $result = mysql_query($query);
  if (!$result) die ("Database access failed: " . mysql_error());
  if(mysql_num_rows($result)>0){
     $row=mysql_fetch_array($result);
     $ans = "<p>The number of names in the DB is: {$row['n1']}</p>";
  }
}
?>
<form method="post">
   <input type="submit" name="sendme" value="Answer here" />
</form>
<?php 
  if(isset($ans))echo $ans;
?>

**NOT CHECKED**

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.