Jump to content

Recommended Posts

Hi guys,

 

I had previously posted in the mysql forum and those guys over there were really helpful... but turned out that my supervisor now wants to try it on postgresql.

 

I'm new to php and postresql, I mean I can't even write you a single line. :)

 

My project is that I need to have a php page that will read off the database and generate outputs of 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 simply say as follows..

 

 

Thanks for Caring and Donating to the Hurricane Dean Relief Fund.

 

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

 

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

 

Thanks for any and all help.

Link to comment
https://forums.phpfreaks.com/topic/66517-in-need-of-some-help-on-a-project/
Share on other sites

This sounds like it might be better suited for the freelancing section since you're basically asking for someone to write the code for you, but since it's such a small snippet, I'll just post something here... hope it is of some help to you:

<?php
$HOST = ''; // your postgres hostname
$USER = ''; // your DB username
$PASS = ''; // your DB password
$NAME = ''; // your DB name to which you need to connect

$count = 0;
$amt   = 0;
if (($con = pg_connect("host=$HOST user=$USER password=$PASS dbname=$NAME")) === FALSE) {
  // Connection Error
} else {
  $sql = pg_query("SELECT COUNT(amount) as count, SUM(amount) AS total FROM tableName");
  if ($sql === FALSE) {
    // Query Error
  } else {
    $res = pg_fetch_assoc($sql);
    $count = $res['count'];
    $amt   = $res['total'];
  }
}

echo "There have been {$count} donations for \${$amt} to date";
?>

 

Hope this helps point you in the right direction... Keep in mind with postgres that capital letters in your column names can cause you grief since you would have to refer to them within double quotes in all your queries. You're much better off using only lowercase. Also, you could easily combine your date and time into one field with the TIMESTAMP data type, and IMHO, this is much recommended to the alternatives.

 

Good luck.

Thank you very much Obsidian... you've been a whole lot of help.  Looking at your codes I can follow a lil bit. Like I said I've never done anything like this... but I'm willing to learn.

 

Thanks again for all your help.  I really really appreciate it.

Hi again,

 

I used the codes into a php file and uploaded it to the server... and the page was blank...  Is there anyway to print out.. if the connection failed or something?  cause I see..

 

// Connection Error but that's like just a comment right... that's not like an output. Can you help me?

Hi again,

 

I used the codes into a php file and uploaded it to the server... and the page was blank...  Is there anyway to print out.. if the connection failed or something?  cause I see..

 

// Connection Error but that's like just a comment right... that's not like an output. Can you help me?

 

Correct, that is a comment. It's intended for you to place any message or such that you wish to display at those points For instance, you could just do something like:

<?php
// Connection Error
echo "We have a connection error! : " . mysql_error();
?>

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.