Gossamer Forum
Home : General : Internet Technologies :

Another PHP question functions and arrays

Quote Reply
Another PHP question functions and arrays
Ok here is the problem. I am doing a var_dump at the end to make sure I have the correct values in the array; which I do... I get this: array(2) { [0]=> string(3) "232" [1]=> string(3) "132" }

So I should be able to do a return statment and this values should be brough back, right? Wrong. I do another var_dump in the script that requested the function after the function is excuted and I get the same values. Now how do I get the data out of that array?

Here is the code:
Code:
function QUICK_STATS_QUERY(){
global $link;
$query1 = "SELECT count(user_expirydate) FROM users WHERE user_expirydate >= curdate()";
$query2 = "SELECT count(user_expirydate) FROM users WHERE user_expirydate < curdate()";

for($i=0; $i <= 1; $i++){
$query_array = array($query1, $query2);
$QUERY_quickstats = $query_array[$i];
$infoquery_results = mysql_query($QUERY_quickstats, $link) or die("MySQL query infoquery failed. Error if any: ".mysql_error());
$infoquery_results = mysql_fetch_array($infoquery_results); $active_details[$i] = $infoquery_results["count(user_expirydate)"];
}
var_dump($active_details);
return array (0, 1, 2);
}



<?php

CURRENT_DATE();
QUICK_STATS_QUERY();
list ($quick_stats_values) = QUICK_STATS_QUERY();

print <<< END
<table border="0" width="100%">
<tr>
<td width="30%" valign="top"><b>Quick Totals:<br>
</b>Active Accounts: {$quick_stats_values[0]}<br>
Expired Accounts: {$quick_stats_values[1]}<br>
Suspended Accounts: 000
<p><b>Last 7 days:<br>
</b>New Accounts: 000<br>
Renewed Accounts: 000<br>
Expired Accounts: 000</p>
</td>
<td width="50%" valign="top">
<h3>Administration Panel</h3>
</td>
</tr>
</table>
END;
?>

Code:

P.S. Believe it or not but there is more knowledge and wealth at these fourms then most PHP fourms I've been to. You guys are great and I appreciate every last bit of help you guys willingly offer.

Last edited by:

Unquick: Jun 14, 2003, 10:49 AM
Quote Reply
Re: [Unquick] Another PHP question functions and arrays In reply to
Hi there,

I'm not entirely sure what you're trying to accomplish, but what if you try something like the following. (Also, there might be more efficient ways to accomplish this, but I tried to keep the basic approach consistent.) Anyway:

Code:


function QUICK_STATS_QUERY()
{
$query1 = "SELECT count(user_expirydate) FROM users WHERE user_expirydate >= curdate()";
$query2 = "SELECT count(user_expirydate) FROM users WHERE user_expirydate < curdate()";
$query_array = array($query1, $query2);

for($i=0; $i <= 1; $i++){
$infoquery_results = mysql_query($query_array[$i]) or die('MySQL query infoquery failed. Error if any: ' . mysql_error());
$active_details[$i] = mysql_result($infoquery_results,0,0);
}

return $active_details;
}




CURRENT_DATE();
$quick_stats_values = QUICK_STATS_QUERY();

print <<<END
<table border="0" width="100%">
<tr>
<td width="30%" valign="top"><b>Quick Totals:<br>
</b>Active Accounts: $quick_stats_values[0]<br>
Expired Accounts: $quick_stats_values[1]<br>
Suspended Accounts: 000
<p><b>Last 7 days:<br>
</b>New Accounts: 000<br>
Renewed Accounts: 000<br>
Expired Accounts: 000</p>
</td>
<td width="50%" valign="top">
<h3>Administration Panel</h3>
</td>
</tr>
</table>
END;

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund