Array Issue
I've created an array, but am struggling to get the end result I'm looking for - could anyone point me in the right direction?
Current result: http://www.equinefocus.co.uk/random/4l56fdfm/20091230.php
Array
$filters_array = array
(
"Filter001"=>array
(
"<a href="http://www.equinefocus.co.uk" target="blank">Filter 001: Where rating = 1</a>", // filter name and link
"SELECT * FROM timeform WHERE tfr='1'", // count rows - number of qualifiers
"SELECT * FROM timeform WHERE tfr='1' and WHERE pos='1'", // count rows - number of winners
"SELECT tfr, SUM(profit) FROM timeform GROUP BY tfr WHERE tfr='1'" // sum of profit column for qualifiers
),
"Filter002"=>array
(
"<a href="http://www.equinefocus.co.uk" target="blank">Filter 002: Where rating = 2</a>",
"SELECT * FROM timeform WHERE tfr='2'",
"SELECT * FROM timeform WHERE tfr='2' and WHERE pos='1'",
"SELECT tfr, SUM(profit) FROM timeform GROUP BY tfr WHERE tfr='2'"
),
"Filter003"=>array
(
"<a href="http://www.equinefocus.co.uk" target="blank">Filter 001: Where rating = 3</a>",
"SELECT * FROM timeform WHERE tfr='3'",
"SELECT * FROM timeform WHERE tfr='3' and WHERE pos='1'",
"SELECT tfr, SUM(profit) FROM timeform GROUP BY tfr WHERE tfr='3'"
)
); // after final grouping
End Code
<?php
include($_SERVER['DOCUMENT_ROOT'].'/random/4l56fdfm/includes/*****.php'); //connection information
include($_SERVER['DOCUMENT_ROOT'].'/random/4l56fdfm/includes/associative.php'); //array
foreach ($filters_array[0] as $sql)
{
$result = mysql_query($sql);
echo 'Filter name: ' . ($result) . ' xxx';
}
foreach ($filters_array[1] as $sql)
{
$result = mysql_query($sql);
echo 'Qualifiers: ' . mysql_num_rows($result) . ' rows';
}
foreach ($filters_array[2] as $sql)
{
$result = mysql_query($sql);
echo 'Winners: ' . mysql_num_rows($result) . ' rows';
}
foreach ($filters_array[3] as $sql)
{
$result = mysql_query($sql);
echo 'Profit ' . sum($result) . ' rows';
}
?>
Related Article: 2 dimensional array issue
is a PHP discussion thread by loligator that has 5 replies, was last updated 3 years ago and has been tagged with the keywords: array.
Borderline
Junior Poster in Training
56 posts since Apr 2008
Reputation Points: 11
Solved Threads: 1
Skill Endorsements: 0
At a glance it looks to me like your problem would be here:
echo 'Filter name: ' . ($result) . ' xxx';
Looks like you are echoing $result which executes the query. You won't get the desired results if you try to echo that directly.
Thanks for the speedy response. Can you recommend how to get the code working effectively, or point me in the direction of a tutorial dealing with similar issues? I've failed to find one so far. Any further advice would be appreciated.
Borderline
Junior Poster in Training
56 posts since Apr 2008
Reputation Points: 11
Solved Threads: 1
Skill Endorsements: 0
I'm guessing there is something going on in one of your includes that would explain why your queries are written the way they are?
I have to fess up, I was asking for help on a forum, got a partial code, but haven't been able to complete the project there. I'm in way over my head, don't understand how the code works (have only a basic knowledge of php myself) but I do understand the result I'm trying to get (par for the course with amateurs, no doubt!)
The php includes won't shed any more light, one is the connection to the database, and the other is the array shown in my original thread.
Borderline
Junior Poster in Training
56 posts since Apr 2008
Reputation Points: 11
Solved Threads: 1
Skill Endorsements: 0