Jump to content

Beginners Project, but still clueless on what to do.


cuboidgraphix

Recommended Posts

Hi guys,

 

I'm new to php and mysql and I have a lil project.

 

My project is that I need to have a php page that will read off a mysql database and output two individual values..

 

For example... I will have tables that say..

 

Date | Hour | Tel | Amount

 

07.08.21 | 20:01:02 | 6701064 | 5

07.08.21 | 20:01:04 | 6701065 | 10

 

and so on... 

 

Now my php page needs to say simply as follows..

 

 

Thanks for Caring

 

So far there has been 2 (# on database) donations...

We have gathered an amount of $15 (amount on database)

 

Those in bold are the two things that are to be read off the mysql database.

 

Now I have to admit I don't have a clue on how to start... so if anyone can write me the codes I would really appreciate it... I'll fill the server stuff later. 

 

I know it must be fries to ya'll but it's like rocket science to me.

 

Thanks again.

 

 

Link to comment
Share on other sites

$query = mysql_query("SELECT * FROM table");
$rows = mysql_num_rows($query);
while($values = mysql_fetch_array($query)){
      $sum += $values['amount'];
}
echo "So far there has been $rows donations" . "<br/>";
echo "We have gathered an amount of \$$sum";

 

There may be easier methos with mysql commands like COUNT and SUM, but as im not very good with those and ure a beginner, try with this code.

Link to comment
Share on other sites

The other way would work but you would get a miss count if the amount was 0 or less

 

you basicly do two queries (sure you could do with one)

1 - Count Row's with a value greater the Zero

$query = "select count(*) from table where Amount > 0";
$CntRecordQuery = mysql_query($query);
$Cntvar=mysql_result($CntRecordQuery,0,"count(*)");

2 - Sum up the Amount

$query = "select sum(Amount) as TotalAmount from table";
$result = mysql_query($query);
$Totalamount = $result['TotalAmount'];

 

echo "So far there has been $Cntvar donations<br>";
echo "We have gathered an amount of $Totalamount";

 

 

Link to comment
Share on other sites

Hehehe... no offense guys, but I mean I'm like a sperm beginner.  lol 

 

how do I integrate that into a php page?  where I could just like copy and paste.... I mean.. Including the php codes for the page..

 

and the mysql codes to connect and stuff...

 

Let me explain.. I've seen some php&mysql codes.. but don't exactly understand it.

 

So if you could write me the whole php and mysql codes that would really help me out.

Link to comment
Share on other sites

Or the two codes by jvrothjr coupled in one:

 

$query = mysql_query("SELECT COUNT(amount), SUM(amount) FROM table WHERE amount>0");
$sum = mysql_result($query, 0, "SUM(amount)");
$count = mysql_result($query, 0, "COUNT(amount)");
echo "So far there has been $count donations" . "<br/>";
echo "We have gathered an amount of \$$sum";

 

This kind of code may be a bit complicated for a new starter. Anyway its u chosing ;)

Link to comment
Share on other sites

Thats not what this is for its for you to learn from there is a forum for asking some one to right the code for you. The general user don't have the time to do that for you.

 

You posted in the help forum and this is what you got. sry maybe in the moring its bed time

Link to comment
Share on other sites

lol. U need some tutorials to start off, but this is a help forum for specific stuff. Try google and ull find a lot of tutorials. Im just writing the full code also with the connect:

 

$connect = @mysql_connect('mysql server host', 'username', password') or die('cant connect);
mysql_select_db('database_name');
$query = mysql_query("SELECT COUNT(amount), SUM(amount) FROM table WHERE amount>0");
$sum = mysql_result($query, 0, "SUM(amount)");
$count = mysql_result($query, 0, "COUNT(amount)");
echo "So far there has been $count donations" . "<br/>";
echo "We have gathered an amount of \$$sum";
mysql_close($connect);

 

Adjusting the host, user, pass, database name, tables and columns to fit your data, u will end up with what u first wanted.

Link to comment
Share on other sites

Sorry I'm a lil bit too demanding guys... I do apologize.  And I do appreciate all of your help. But this project was given to me at work.. and I have like a day to find out how to do it... Not part of my job description, but I guess they felt as they could count on me to get it done.. so I was imploring you guys for help..

 

 

Again, sorry for being too pushy... and thanks for all your help.

 

Now that I've got this... they've told me to try it on PostgreSQL ... this really sucks.. I'll have to go bother some poor souls in the other sub forum..

 

Thanks again.. you're a life saver.

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.