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

Link to comment
Share on other sites

[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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

<?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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.