PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<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
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:
<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>
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.
<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>
<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>
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.
<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>
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 .