Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So i am assuming that you have one table <code>donations</code> where you have some <code>donId</code> (reference No.) of the donation, <code>donName</code> of the person donating, <code>donCountry</code> the country the donator is from and <code>donAmount</code> how much money they donated. Your file would look something like this (i will not bother with all the proper headers for html, so the result will not be a w3c valid html but it should work in your browser without problems.</p> <p>I think i MUST say that you should not use the <code>mysql_query</code> and all other <code>mysql_...</code> functions use instead <code>mysqli_*</code>. The following code though is still using the old these days already deprecated mysql_ functions, so it's in your interest to upgrade it accordingly to mysqli (that's a home work ;) lol )</p> <p><br/>File <code>donInfo.php</code>:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form action='donInfo.php' method='post'&gt; &lt;label for='donId'&gt;Reference No.:&lt;/label&gt; &lt;input type='text' size='6' name='donId' id='donId' value='' /&gt; &lt;input type='submit' name='do' value=' Show me! ' style='margin-left:2em;'/&gt; &lt;/form&gt; &lt;?php /* table definition: CREATE TABLE donations ( donId int unsigned not null, donCountry varchar(80) not null, donName varchar(80) not null, donAmount numeric(11,2) not null, PRIMARY KEY (donId) ) */ if (!isset($_POST['do']) || !isset($_POST['donId']) || !$_POST['donId']) exit; require_once 'connection.php'; $don=mysql_fetch_assoc( mysql_query('SELECT * '. 'FROM donations '. 'WHERE donId="'.mysql_real_escape_string($_POST['donId'],$con).'"',$con)); if ($don===false || !$don['donId']) print '&lt;h3&gt;Donation id #'.$_POST['donId'].' does not exist!&lt;/h3&gt;'; else { print '&lt;h3&gt;Information about donation id #'.$_POST['donId'].'&lt;/h3&gt;'. 'State: '.$don['donCountry'].'&lt;br/&gt;'. 'Donator: '.$don['donName'].'&lt;br/&gt;'. 'Amount: $ '.number_format($don['donAmount'],2).'&lt;br/&gt;'. '&lt;hr/&gt;'; $sumP=mysql_fetch_assoc( mysql_query('SELECT SUM(donAmount) total, COUNT(*) donx '. 'FROM donations '. 'WHERE donName="'.mysql_real_escape_string($don['donName'],$con).'" '. 'GROUP BY donName',$con)); print '&lt;h4&gt;Donations from '.$don['donName'].':&lt;/h4&gt;'. 'Total Amount: $ '.number_format($sumP['total'],2).'&lt;br/&gt;'. 'Donated &lt;b&gt;'.number_format($sumP['donx'],0).'&lt;/b&gt; times to date.&lt;br/&gt;'. '&lt;hr/&gt;'; $sumC=mysql_fetch_assoc( mysql_query('SELECT SUM(donAmount) total, COUNT(DISTINCT donName) donators, COUNT(*) donx '. 'FROM donations '. 'WHERE donCountry="'.mysql_real_escape_string($don['donCountry'],$con).'" '. 'GROUP BY donCountry',$con)); print '&lt;h4&gt;Donations from '.$don['donCountry'].':&lt;/h4&gt;'. 'Total Amount: $ '.number_format($sumC['total'],2).'&lt;br/&gt;'. 'Total of &lt;b&gt;'.number_format($sumC['donx']).'&lt;/b&gt; donations from &lt;b&gt;'.number_format($sumC['donators'],0).'&lt;/b&gt; donators.&lt;br/&gt;'. '&lt;hr/&gt;'; $sumW=mysql_fetch_assoc( mysql_query('SELECT SUM(donAmount) total, COUNT(DISTINCT donName) donators, COUNT(DISTINCT donCountry) countries, COUNT(*) donx '. 'FROM donations '. 'GROUP BY 1=1',$con)); print '&lt;h4&gt;Donations Total:&lt;/h4&gt;'. 'Total Amount: $ '.number_format($sumW['total'],2).'&lt;br/&gt;'. 'Total of &lt;b&gt;'.number_format($sumW['donx']).'&lt;/b&gt; donations from &lt;b&gt;'.number_format($sumW['countries'],0).'&lt;/b&gt; countries and &lt;b&gt;'.number_format($sumW['donators'],0).'&lt;/b&gt; donators.&lt;br/&gt;'. '&lt;hr/&gt;'; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I have tested the code, so it should work well. i'm using your <code>connection.php</code> script where (i guess) you are initializing your database.</p> <p>short description of what it does: Asks for an ID, then when submited it checks whether it exist or not and if yes, it will print information about THAT donation id, information about user of that id, about country of that id and total donation statistic. If the donation Id does not exist, it will just say: does not exist while waiting for another ID to be entered.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload