Member Avatar for Borderline

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';
}

?>

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.

Member Avatar for Borderline

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.

Fist I see that you are executing the query $sql

$result = mysql_query($sql);

But I don't see where you have $sql defined. For example:

$sql = "SELECT * FROM timeform WHERE tfr='1'",	 // count rows - number of qualifiers

$result = mysql_query($sql); Would execute the above query. You should also be ending the query with a semicolon. I write everything using conventional PHP (although I shouldn't) so I'm not really on the top of my game with OOP. 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?

Member Avatar for Borderline

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.

By the looks of it there is a few things going on there that is causing a problem. Not quite sure where to tell you to start on that one.

There are member's here that are Pros at this and perhaps they could be of more help.

If you have an understanding of the basics and you know what you want your end result to be I would suggest writing the code yourself and simplify it a bit by using what you know. Stick with what you understand and you will never truly be in over your head. There are plenty of tutorials out there that will get you pointed in the right direction.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.