Jump to content

Pull amount of rows in MYSQL table and display?


jackmcnally

Recommended Posts

Hi,

 

I have a 'pre-release' sign up form, where people put in their email address and name, and it transmits to a MYSQL database. That's working fine. What I want to do is to have a piece of text that reads:

 

(insert pre release amount of signer upperers here) have signed up. Will you?

 

I'm guessing that the amount of rows on the table, would end up being the number. How do I do this?

 

Thanks,

Jack

[quote author=jackmcnally link=topic=348213.msg1643088#msg1643088 date=1321769606

I have a 'pre-release' sign up form, where people put in their email address and name, and it transmits to a MYSQL database. That's working fine.

 

If you have what you say you do above, then you should already know how to do all that. Unless that is you didn't write the code for the sign up form.

Hi,

 

Sorry for my very late reply, I have been busy! I did copy the script, but I have now wrote it myself. I have the form submitting to a PHP file (code shown below), that connects to the database and table and inputs the information provided.

 

<?php
header( 'Location: http://www.xxxxxx.com/yes.php' ) ;

$con = mysql_connect("localhost","xxxxxx","xxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxxxx", $con);

$sql="INSERT INTO benotified (email, firstname, lastname)
VALUES
('$_POST[email]','$_POST[firstname]','$_POST[lastname]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con)

?>

 

It works like a charm. I have tried using a modified version of it, including your function (as shown below), but Dreamweaver is telling me I have a syntax error.

 

<?php

$con = mysql_connect("localhost","xxxxx","xxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxxxx", $con);

SELECT COUNT(*) FROM xxxxx


mysql_close($con)

?>

 

As previously stated, I'm a wee bit of a PHP noob, but I am making pretty good progress with some tutorials! I learnt how to echo and write some basic stuff today without assistance! Yay!  :D

 

Thanks for all the help, I really appreciate it!

Sounds like you want:

 

 


$result = mysql_query("SELECT * FROM tablename", $con);
$num_rows = mysql_num_rows($result);

echo $num_rows . " " . "have signed up. Will you? ";   

 

Num rows counts how many rows of data you have in your specified table. http://uk.php.net/manual/en/function.mysql-num-rows.php

 

Drongo

<?php

$con = mysql_connect("localhost","xxxxx","xxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxxxx", $con);

SELECT COUNT(*) FROM xxxxx


mysql_close($con)

?>

 

I gave you a query to run. You can't simple write a query into the PHP code and expect it to do anything. This is very basic stuff. Besides you shouldn't have different DB connection scripts. You should only have one that any page which needs DB access should include.

 

$con = mysql_connect("localhost","xxxxx","xxxxx");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("xxxxx", $con);

$query = "SELECT COUNT(*) FROM xxxxx";
$result = mysql_query($query);
$count = mysql_result($result, 0);

echo "{$count} have signed up. Will you? ";

mysql_close($con)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.