Page 2 of 3
Posted: Wed Nov 28, 2007 6:44 pm
by drewrockshard
ianhull wrote:show me exactly what comes from the date column of the db.
for example, is it
November 2007
or November (2007)
or a UNIX timestamp?
Thanks
The SQL statement shows this:
As for the drop down menu - It gets the same thing (2007-11-22) - but I use this
To reformat the drop down menu.
Posted: Wed Nov 28, 2007 6:46 pm
by ianhull
Right, I should be able to do this now.
I needed
Give me 1 hour as I need to pop out for ciggies too

Posted: Wed Nov 28, 2007 6:54 pm
by drewrockshard
Hah!
Awesome!

Thanks again, I'll be monitoring this thread.
Let me know.
Posted: Wed Nov 28, 2007 7:25 pm
by ianhull
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 date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC";
$dateResult = mysql_query($dateQuery) or die(mysql_error());
$num = mysql_num_rows($dateResult);
while ($i<$num) {
$zDate = mysql_fetch_assoc($dateResult);
$yDate = $zDate['date'];
$xDate = date('M (Y)', strtotime($yDate));
//added tempDate array
$tempDate = array();
$tempYDate = substr($yDate, 0, 4);
if(in_array($tempDate, $tempYDate)){
//do nothing
}else{
echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
};//end if
$tempDate[] = $yDate;
$i++;
}
?>
</optgroup>
</select>
Posted: Wed Nov 28, 2007 7:31 pm
by ianhull
Would probably help if I put the array in the right order
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 date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC";
$dateResult = mysql_query($dateQuery) or die(mysql_error());
$num = mysql_num_rows($dateResult);
while ($i<$num) {
$zDate = mysql_fetch_assoc($dateResult);
$yDate = $zDate['date'];
$xDate = date('M (Y)', strtotime($yDate));
//added tempDate array
$tempDate = array();
$tempYDate = substr($yDate, 0, 4);
if(in_array($tempYDate, $tempDate)){
//do nothing
}else{
echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
};//end if
$tempDate[] = $yDate;
$i++;
}
?>
</optgroup>
</select>
Posted: Wed Nov 28, 2007 7:51 pm
by ianhull
tooooo, many mistakes now, i guess it's time for bed for me soon
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 date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC";
$dateResult = mysql_query($dateQuery) or die(mysql_error());
$num = mysql_num_rows($dateResult);
while ($i<$num) {
$zDate = mysql_fetch_assoc($dateResult);
$yDate = $zDate['date'];
$xDate = date('M (Y)', strtotime($yDate));
//added tempDate array
$tempDate = array();
$tempYDate = substr($yDate, 0, 4);
if(in_array($tempYDate, $tempDate)){
//do nothing
}else{
echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
};//end if
$tempDate[] = $tempYDate;
$i++;
}
?>
</optgroup>
</select>
Posted: Wed Nov 28, 2007 7:53 pm
by drewrockshard
Hey,
Alright - better - but still no cigar.
No errors in the log files anymore. However, I am still getting multiple items in the drop down. Pretty much, however many results I get from the database (say I have 3 date results from the mysql query for November 2007), then I get 3 options from the drop down. So right now, after adding the code, I have three drop down options of:
November 2007
November 2007
November 2007
Posted: Wed Nov 28, 2007 7:56 pm
by ianhull
Did you try the last one, or was you typing your reply?
Posted: Wed Nov 28, 2007 8:00 pm
by drewrockshard
Hey,
Yuppers - that's with that last bit of code you sent me. No errors - but I do have 3 drop downs of:
November 2007
November 2007
November 2007
Posted: Wed Nov 28, 2007 8:05 pm
by ianhull
Try this one, let me know how it goes
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 date FROM walkthroughs WHERE user='$authUser' ORDER BY date DESC";
$dateResult = mysql_query($dateQuery) or die(mysql_error());
$num = mysql_num_rows($dateResult);
while ($i<$num) {
$zDate = mysql_fetch_assoc($dateResult);
$yDate = $zDate['date'];
$xDate = date('M (Y)', strtotime($yDate));
//added tempDate array
$tempDate = array();
$tempYDate = substr($yDate, 0, 7);
if(in_array($tempYDate, $tempDate)){
//do nothing
}else{
echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
};//end if
$tempDate[] = $tempYDate;
$i++;
}
?>
</optgroup>
</select>
DONT FORGET DISTINCT IN THE SELECT

Posted: Wed Nov 28, 2007 8:09 pm
by drewrockshard
Darn ...
Same results.
Posted: Wed Nov 28, 2007 8:10 pm
by ianhull
even with DISTINCT?
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);
while ($i<$num) {
$zDate = mysql_fetch_assoc($dateResult);
$yDate = $zDate['date'];
$xDate = date('M (Y)', strtotime($yDate));
//added tempDate array
$tempDate = array();
$tempYDate = substr($yDate, 0, 7);
if(in_array($tempYDate, $tempDate)){
//do nothing
}else{
echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
};//end if
$tempDate[] = $tempYDate;
$i++;
}
?>
</optgroup>
</select>
Posted: Wed Nov 28, 2007 8:19 pm
by drewrockshard
Alright!
Improvements

- still not there yet.
Now, with DISTINCT, I get only two results instead of 3. After looking through the source of the HTML code (in IE or Firefox), it shows that it is giving the two results the value of:
If I DO NOT use DISTINCT i get:
So, it looks like if there are two of the same days - it doesn't display both days, but if there are two different days (but the same month), then it still displays mutliple entries in the dropdown.
Hope the additional info has helped.
Posted: Wed Nov 28, 2007 8:26 pm
by ianhull
Yes it has helped,
I think the issue now is with the substr()
try this one, see if there is any luck.
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);
while ($i<$num) {
$zDate = mysql_fetch_assoc($dateResult);
$yDate = $zDate['date'];
$xDate = date('M (Y)', strtotime($yDate));
//added tempDate array
$tempDate = array();
$tempYDate = substr($yDate, 0, -3);
if(in_array($tempYDate, $tempDate)){
//do nothing
}else{
echo "<option name=\"dropdate\" value=\"$yDate\">".$xDate."</option>";
};//end if
$tempDate[] = $tempYDate;
$i++;
}
?>
</optgroup>
</select>
Posted: Wed Nov 28, 2007 8:31 pm
by drewrockshard
Man, this script is really kickin my ass.
Here's the results again (2 drop downs, 3 database results):
2007-11-27
2007-11-22