Jump to content

Extracting specific dates from a for loop


OutOfInk

Recommended Posts

I want to extract the MIN, MAX AND ROUND from the database. Can i get the result i want through making $count[][][] into a multiple array ?
 
$rouCount = mysql_num_rows(mysql_query("SELECT MIN(Date) , MAX(Date) , `Round` FROM `GameRound`"));
 
for ($i = 0; $i < $rouCount; $i++){
$count = mysql_fetch_row(mysql_query("SELECT MIN(Date) , MAX(Date) , `Round` FROM `GameRound`"));
foreach ($count as $k => $lokk){
$a = $lokk;
echo "Rounds $a[0] $a[1] $a[2]<br />";
}
}
 
Eventually I need it to display;
Round 1 2014-03-14 2014-03-23
Round 2 2014-03-24 2014-03-29
Round 3 2014-04-14 2014-04-23
Round 4 2014-05-24 2014-05-29
 
atm i get;
Rounds 2 0 1
Rounds 2 0 1
Rounds 1 
 
Link to comment
Share on other sites

the main reason i asked what your data is, that you expect to produce that output from, is because your posted query and code don't convey useful information.

 

that query will only return one row, with the min of all dates, max of all dates, and the first encountered round number. you likely need a GROUP BY Round term in the query.

 

your code is running that query once to get a count, then running that same exactly query again inside of a loop. your goal is to run one (or as few as possible) queries that gets the data you want in the order that you want it. there's no point in this. just run the query and loop over the row(s) it returns.

 

your code that is iterating over the single row from that query is displaying three values, for the three things that query is selecting, min, max, and rounds. the output is "Rounds" followed by the first three characters of the minimum date found, "Rounds" followed by the first three characters of the maximum date found, then "Rounds" followed by the first three characters of the first encountered round number. i recommend you first study up on retrieving data from a query as this step in your code is nonsense.

 

this is a case where rather than posting what you have tried (because it doesn't tell us anything useful), you need to post your data (enough of it to show anyone wanting to help what they would need to know to produce the specific output you expect from that data) and post the excepted output (which we already know.) if the data you are posting doesn't clearly correspond to the output you have shown from that data, don't bother posting it as it won't help anyone to help you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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