Jump to content


Photo

Dividing data with php after sql query....


  • Please log in to reply
2 replies to this topic

#1 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 25 October 2006 - 01:02 PM

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....

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 25 October 2006 - 01:26 PM

The SQL's date functions are much better than PHP's ones. If you want to do it with php you'll have to convert the dates into timestamps, preform the matematical operations needed and then convert back to the date you want, compare....

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 mkosmosports

mkosmosports
  • Members
  • PipPipPip
  • Advanced Member
  • 196 posts

Posted 25 October 2006 - 01:38 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users