Jump to content

Dividing data with php after sql query....


mkosmosports

Recommended Posts

Hello Everyone,

I need to retrieve startdates from mysql database in several date ranges, but I want to avoid having to run a separate query each time, so what I want to achieve is run one query with a larger date range and then retrieve the data I need using php. Then, I want to put that data, separated by date range conditions, into individual containers but without having the container take part in the while loop....

Anyone know what I mean, ever had similar issues or know of a solution to this? Below is the code...
Currently:
$result7 = @mysql_query("SELECT START_DATE FROM sf_group_team WHERE START_DATE BETWEEN '2006-07-01' AND '2006-07-20'"); //Retrieves all startdates between a selected date range....

Followed by:
  echo("<div class=\"teamlistcupcontainer\">"); //Main container.
  echo("<div>"); //Subcontainer that stores each data set.
  while ($row = mysql_fetch_array($result7)) //I have a separate while loop for every query with different date ranges.
        {
          include("phps/retteamscup.php");
        }
  echo("</div>");
  echo("</div>");

Ideally, what I would want is:
$result7 = @mysql_query("SELECT START_DATE FROM sf_group_team WHERE START_DATE BETWEEN '2006-01-01' AND '2006-12-30' "); //One query that retrieves all possible startdates in 2006....

  echo("<div class=\"teamlistcupcontainer\">");
  while ($row = mysql_fetch_array($result7))
            {
                  $startdate = $row["START_DATE"];

                            if ($startdate => "2006-07-01" && $startdate <= "2006-07-20") <-- Break up the                         
                            data (not sure if conditions are what I need here....)
          echo("<div>"); <-- This is the subcontainer in which I want to store separated data, 
                          but I dont want it to loop...(only once per each data set..)
                            {
                include("phps/retteamscup.php");
              }
          echo("</div>");<-- End tag to subcontainer (only once per each data set..)             
                          }
          echo("</div>");

Thanks Everyone!
Please let me know if Im not clear....
Link to comment
https://forums.phpfreaks.com/topic/25049-dividing-data-with-php-after-sql-query/
Share on other sites

Hey Orio,

Thanks for your answer. So youre suggesting to just run multiple queries. Im all for that, it is a much simpler solution to code. I just thought running one query and breaking up the data with php would be quicker. I was gonna run a time test actually, but havent been able to get the php method to work as desired, so unable to actually compare. I doubt the time difference would be big between the two methods though, right?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.