Displaying results from a query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Displaying results from a query

Post by reverend_ink »

I am having trouble displaying information from a query... any help would be great...

Thanks in advance....

Here is the hardcoded data:

Code: Select all

<?php echo
bar_graph(
  "hBar",
  "150, 167, 250, 341, 35, 117, 47, 201, 124, 98, 211",
  "7-1-2003,7-2-2003,7-3-2003,7-4-2003,7-5-2003,7-6-2003,7-7-2003,7-8-2003,7-9-2003,7-10-2003,7-11-2003",
  1,
  "Valid W/D"
)

?>
And here is the dynamic code, need the two lines under "hBar" to display like shown above:

Code: Select all

<?php

@mysql_connect($host, $loginname, $password) or die(mysql_error()); 
@mysql_select_db($data) or die('Could not select database'.mysql_error()); 

	$result = mysql_query("SELECT SUM(num_TransactionAmount) as trans, dte_Settlement, num_TransactionAmount
	FROM tbl_ATME_Data
	WHERE 	dte_Settlement BETWEEN '2002-01-01' AND '2002-01-07' AND num_TerminalID = '$txt_TerminalID' GROUP by dte_Settlement LIMIT 31");

while ($r = mysql_fetch_array($result)) &#123;

echo
bar_graph(
  "hBar",
  "".$r&#1111;'trans'].",",
  "".$r&#1111;'dte_Settlement'].",",
    1,
  ""
);

&#125;
?>
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

This should work

Post by thomas777neo »

Code: Select all

<?php 

@mysql_connect($host, $loginname, $password) or die(mysql_error()); 
@mysql_select_db($data) or die('Could not select database'.mysql_error()); 

$result = mysql_query("
SELECT SUM(num_TransactionAmount) as trans, dte_Settlement,num_TransactionAmount 
FROM tbl_ATME_Data 
WHERE dte_Settlement 
BETWEEN '2002-01-01' AND '2002-01-07' 
AND num_TerminalID = '$txt_TerminalID' 
GROUP by dte_Settlement LIMIT 31"); 

$i=0;
$newArray&#1111;0]&#1111;"numrows"]=mysql_num_rows($result);
while ($newArray&#1111;0]&#1111;"numrows"]>$i)
&#123;

$newArray&#1111;$i]&#1111;"trans"]=mysql_result($result ,$i,"trans");
$newArray&#1111;$i]&#1111;"dte_Settlement"]=mysql_result($result ,$i,"dte_Settlement");
$newArray&#1111;$i]&#1111;"num_TransactionAmount "]=mysql_result($result ,$i,"num_TransactionAmount ");

$trans=$newArray&#1111;$i]&#1111;"trans"];

echo $trans;

$i++;
&#125; 

?>
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

or just string build within the while loop to create a comma seperated list

Code: Select all

$trans = '';
$dte_set = '';
while($r = mysql_fetch_array($result))
{
$trans .= $r['trans'] . ', ';
$dte_set .= $r['dte_Settlement'] . ', ';
$num_tran = $r['num_TransactionAmount'];
}

$trans = substr($trans, 0, -2);
$dte_set = substr($dte_set, 0, -2);
you should then have $trans = '150, 167, 250, 341, 35, 117, 47, 201, 124, 98, 211' and $dte_set equal to a string of the dates.

then once the while loop is closed, you can run the graph function

Code: Select all

bar_graph(
 "hBar",
 $trans,
 $dte_set,
 $num_tran,
 "Valid W/D");
reverend_ink
Forum Contributor
Posts: 151
Joined: Sun Apr 20, 2003 1:18 am
Location: Las Vegas | London

Post by reverend_ink »

Worked great! Thanks!

You guys rock!!!!
Post Reply