Passing Variables to Querys
Posted: Thu Aug 31, 2006 3:50 am
feyd | Please use
Basically I want the query to run 12 times on the same page, and display the resuts in 12 different places. I could repeat this code 12 times but is there a way to use an array or something similar?
The data is in a table of transactions throughout the year and I want to retrieve totals per month per user. (and eventually per category as well, but I haven't got to that yet.)
Hope this makes sense!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have created a query below: I need to know how to pass different values of $monthid to the query.Code: Select all
<?php
$currentuser_GetData = "dave";
if (isset($_SESSION['MM_Username'])) {
$currentuser_GetData = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
$monthnum_GetData = "6";
if (isset($monthid)) {
$monthnum_GetData = (get_magic_quotes_gpc()) ? $monthid : addslashes($monthid);
}
mysql_select_db($database_Connect, $Connect);
$query_GetData = sprintf("SELECT sum(transactions.amount) FROM transactions WHERE MONTH(transactions.date) = %s AND transactions.userlogged = \"%s\"", $monthnum_GetData,$currentuser_GetData);
$GetData = mysql_query($query_GetData, $Connect) or die(mysql_error());
$row_GetData = mysql_fetch_assoc($GetData);
$totalRows_GetData = mysql_num_rows($GetData);The data is in a table of transactions throughout the year and I want to retrieve totals per month per user. (and eventually per category as well, but I haven't got to that yet.)
Hope this makes sense!
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]