Page 3 of 3

Posted: Wed Nov 28, 2007 8:35 pm
by ianhull
Right, lets try something else to see what were getting in the array

Code: Select all

<select id="dcdate" name="dcdate"> 
                <optgroup label="Please Select Date"> 
                        <option name="dropdate" value="0">Please Select</option> 
                <?php 
                        $i=0; 
                        $dateQuery = "SELECT DISTINCT date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC"; 
                        $dateResult = mysql_query($dateQuery) or die(mysql_error()); 
                        $num = mysql_num_rows($dateResult); 
//added tempDate array
								$tempDate = array();
                        while ($i<$num) { 
                                $zDate = mysql_fetch_assoc($dateResult); 
                                $yDate = $zDate['date']; 
                                $xDate = date('M (Y)', strtotime($yDate));
								
								
								//yDate format = 0000-00-00
								
								//substr() below should now make a format of 0000-00 which is year and month
								
								//lets empty the tempYDate to ensure it is empty
								$tempYDate = '';
								$tempYDate = substr($yDate, 0, -3);
								
								
								//this is a test to see whats in the array
								print_r($tempDate);
								
								
								//the first if in_array() is NULL as we have not yet added anything to tempDate array
								if(in_array($tempYDate, $tempDate)){
								//do nothing
								}else{
								 
                                echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
								};//end if
								
								//now we add to the tempDate array the tempYDate which formats like 0000-00
								$tempDate[] = $tempYDate;
                                $i++; 
                        } 
                ?> 
                </optgroup> 
        </select>
I just changed the array location as I placed it in the loop :idea:

let me know what you get.

Posted: Wed Nov 28, 2007 8:41 pm
by drewrockshard
Since it wouldn't output to the screen cause it was inside a drop down .. I had to pull it outside of the dropdown to the screen. However, here's the output:

Code: Select all

Array ( ) Nov (2007)Array ( ) Nov (2007)

Posted: Wed Nov 28, 2007 8:45 pm
by ianhull
mmm, this is getting weired :)

Code: Select all

<select id="dcdate" name="dcdate"> 
                <optgroup label="Please Select Date"> 
                        <option name="dropdate" value="0">Please Select</option> 
                <?php 
                        $i=0; 
                        $dateQuery = "SELECT DISTINCT date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC"; 
                        $dateResult = mysql_query($dateQuery) or die(mysql_error()); 
                        $num = mysql_num_rows($dateResult); 
//added tempDate array
								$tempDate = array();
                        while ($i<$num) { 
                                $zDate = mysql_fetch_assoc($dateResult); 
                                $yDate = $zDate['date']; 
                                $xDate = date('M (Y)', strtotime($yDate));
								
								
								//yDate format = 0000-00-00
								
								//substr() below should now make a format of 0000-00 which is year and month
								
								//lets empty the tempYDate to ensure it is empty
								$tempYDate = '';
								$tempYDate = substr($zDate['date'], 0, -3);
								
								
								//this is a test to see whats in the array
								//print_r($tempDate); = Array ( ) Nov (2007)Array ( ) Nov (2007)
								//this is strange because it has "Nov" and it should have "11", it should not have changed, because only xDate has been strtotime();
								
								
								//the first if in_array() is NULL as we have not yet added anything to tempDate array
								if(in_array($tempYDate, $tempDate)){
								//do nothing
								}else{
								 
                                echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
								};//end if
								
								//now we add to the tempDate array the tempYDate which formats like 0000-00
								$tempDate[] = $tempYDate;
                                $i++; 
                        } 
                ?> 
                </optgroup> 
        </select>

Posted: Wed Nov 28, 2007 8:50 pm
by drewrockshard
Saweeeeeet.

It works. I'm going to change a few things up a big (add crap to the DB) to make sure it works for good. Literally I'm going to add a few more dates to make sure it keeps only one result, but I think this is great! I really have appriciated the help. Let me just check this real fast and I'll reply with the results.

Posted: Wed Nov 28, 2007 8:55 pm
by drewrockshard
Hey man,

Okay, I just have one request. Would there be anyway to make the value of each option to be yyyy-mm instead of yyyy-mm-dd?

Other than that, it's lookin good :)

Posted: Wed Nov 28, 2007 8:58 pm
by ianhull
oh, glad it's working :D

yes no problem.

try this

Code: Select all

<select id="dcdate" name="dcdate"> 
                <optgroup label="Please Select Date"> 
                        <option name="dropdate" value="0">Please Select</option> 
                <?php 
                        $i=0; 
                        $dateQuery = "SELECT DISTINCT date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC"; 
                        $dateResult = mysql_query($dateQuery) or die(mysql_error()); 
                        $num = mysql_num_rows($dateResult); 
//added tempDate array
								$tempDate = array();
                        while ($i<$num) { 
                                $zDate = mysql_fetch_assoc($dateResult); 
                                $yDate = $zDate['date']; 
                                $xDate = date('M (Y)', strtotime($yDate));
								
								
								//yDate format = 0000-00-00
								
								//substr() below should now make a format of 0000-00 which is year and month
								
								//lets empty the tempYDate to ensure it is empty
								$tempYDate = '';
								$tempYDate = substr($zDate['date'], 0, -3);
								
								
								//this is a test to see whats in the array
								//print_r($tempDate); = Array ( ) Nov (2007)Array ( ) Nov (2007)
								//this is strange because it has "Nov" and it should have "11", it should not have changed, because only xDate has been strtotime();
								
								
								//the first if in_array() is NULL as we have not yet added anything to tempDate array
								if(in_array($tempYDate, $tempDate)){
								//do nothing
								}else{
								 
                                echo "<option name=\"dropdate\" value=\"$tempYDate\">".$xDate."</option>";
								};//end if
								
								//now we add to the tempDate array the tempYDate which formats like 0000-00
								$tempDate[] = $tempYDate;
                                $i++; 
                        } 
                ?> 
                </optgroup> 
        </select>

Posted: Wed Nov 28, 2007 9:00 pm
by ianhull

Code: Select all

<select id="dcdate" name="dcdate"> 
                <optgroup label="Please Select Date"> 
                        <option name="dropdate" value="0">Please Select</option> 
                <?php 
                        $i=0; 
                        $dateQuery = "SELECT DISTINCT date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC"; 
                        $dateResult = mysql_query($dateQuery) or die(mysql_error()); 
                        $num = mysql_num_rows($dateResult); 
//added tempDate array
								$tempDate = array();
                        while ($i<$num) { 
                                $zDate = mysql_fetch_assoc($dateResult); 
                                $yDate = $zDate['date']; 
                                $xDate = date('M (Y)', strtotime($yDate));
								
								
								//yDate format = 0000-00-00
								
								//substr() below should now make a format of 0000-00 which is year and month
								
								//lets empty the tempYDate to ensure it is empty
								$tempYDate = '';
								$tempYDate = substr($zDate['date'], 0, -3);
								
								
								//this is a test to see whats in the array
								//print_r($tempDate); = Array ( ) Nov (2007)Array ( ) Nov (2007)
								//this is strange because it has "Nov" and it should have "11", it should not have changed, because only xDate has been strtotime();
								
								
								//the first if in_array() is NULL as we have not yet added anything to tempDate array
								if(in_array($tempYDate, $tempDate)){
								//do nothing
								}else{
								 
                                echo "<option name=\"dropdate\" value=\"$yDate\">".$tempYDate."</option>";
								};//end if
								
								//now we add to the tempDate array the tempYDate which formats like 0000-00
								$tempDate[] = $tempYDate;
                                $i++; 
                        } 
                ?> 
                </optgroup> 
        </select>

Posted: Wed Nov 28, 2007 9:08 pm
by drewrockshard
Woopsie. Misunderstanding.

I like how it used to look with the Month and the year. That was for what was between the <select> tags. But theres a separate HTML attribute for <select> .. the part for value="". In the value attribute, I'd like to make it yyyy-dd.

So this is what it looks like now:

Code: Select all

<option name="dropdate" value="2007-11-28">November 2007</option>
And I'd like it to be:

Code: Select all

<option name="dropdate" value="2007-11">November 2007</option>

Posted: Wed Nov 28, 2007 9:13 pm
by ianhull

Code: Select all

<select id="dcdate" name="dcdate"> 
                <optgroup label="Please Select Date"> 
                        <option name="dropdate" value="0">Please Select</option> 
                <?php 
                        $i=0; 
                        $dateQuery = "SELECT DISTINCT date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC"; 
                        $dateResult = mysql_query($dateQuery) or die(mysql_error()); 
                        $num = mysql_num_rows($dateResult); 
//added tempDate array
								$tempDate = array();
                        while ($i<$num) { 
                                $zDate = mysql_fetch_assoc($dateResult); 
                                $yDate = $zDate['date']; 
                                $xDate = date('M (Y)', strtotime($yDate));
								
								
								//yDate format = 0000-00-00
								
								//substr() below should now make a format of 0000-00 which is year and month
								
								//lets empty the tempYDate to ensure it is empty
								$tempYDate = '';
								$tempYDate = substr($zDate['date'], 0, -3);
								
								
								//this is a test to see whats in the array
								//print_r($tempDate); = Array ( ) Nov (2007)Array ( ) Nov (2007)
								//this is strange because it has "Nov" and it should have "11", it should not have changed, because only xDate has been strtotime();
								
								
								//the first if in_array() is NULL as we have not yet added anything to tempDate array
								if(in_array($tempYDate, $tempDate)){
								//do nothing
								}else{
								 
                                echo "<option name=\"dropdate\" value=\"$tempYDate\">".$xDate."</option>";
								};//end if
								
								//now we add to the tempDate array the tempYDate which formats like 0000-00
								$tempDate[] = $tempYDate;
                                $i++; 
                        } 
                ?> 
                </optgroup> 
        </select>

Posted: Wed Nov 28, 2007 9:19 pm
by drewrockshard
Awesome! Resolved :)

Taht was great!. 4 pages of forum topic, but we got it goin. What I think is awesome is the fact that forum topics go on and on and on - but we were able to knock this one out cause we were both online and kept replying .. I rarely see that.

I do wanna thank you, and if you have some sort of AIM or any IM system and wanna keep in touch or anything, just PM me. I do alot of side web design (im more of a code monkey / web design (CSS / XHTML) type guy - so I make things look good :P.

Again, thanks :)