Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Software > Adobe Software > Dreamweaver

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-28-2008, 10:57 PM
BROnstott
 
Posts: n/a
Format date/time in dynamic drop down list

Can anyone tell me how to format a drop down list that allows the user to
select a date/time from a list? The game_time_date is a date_time field in
MySQL. The PHP created by Dreamweaver for the select list is to complex for
this novice (attached). I tried using DATE_FORMAT in the recordset to format
the date/time, and also date() in the PhP to format the field; both seem to
break the select list. I want the date/time in the drop down list to display
as "Saturday, Aug 11 1:30 pm". It's stored in MySQL as "2008-08-11 1:30:00".
The form works fine, but the formats aren't user friendly.

Help will be greatly appreciated.

<form id="game_day_form" name="game_day_form" method="post" action="">
<select name="game_date_time_select" id="game_date_time_select">
<option value="1">Please select a day</option>
<?php
do {
?>
<option value="<?php echo
$row_rsGameDateTime['game_date_time']?>"><?php echo
$row_rsGameDateTime['game_date_time']?></option>
<?php
} while ($row_rsGameDateTime = mysql_fetch_assoc($rsGameDateTime));
$rows = mysql_num_rows($rsGameDateTime);
if($rows > 0) {
mysql_data_seek($rsGameDateTime, 0);
$row_rsGameDateTime = mysql_fetch_assoc($rsGameDateTime);
}
?>
</select>
<input type="submit" name="game_day_select2" id="game_day_select2"
value="Select" />
<input name="event_id" type="hidden" id="event_id" value="<?php echo
$row_rsGameDateTime['event_id']; ?>" />
</form>

Reply With Quote
  #2 (permalink)  
Old 07-29-2008, 04:44 PM
Michael Fesser
 
Posts: n/a
Re: Format date/time in dynamic drop down list

..oO(BROnstott)

>Can anyone tell me how to format a drop down list that allows the user to
>select a date/time from a list? The game_time_date is a date_time field in
>MySQL. The PHP created by Dreamweaver for the select list is to complex for
>this novice (attached). I tried using DATE_FORMAT in the recordset to format
>the date/time, and also date() in the PhP to format the field; both seem to
>break the select list.


DATE_FORMAT() would be the preferred method. Let's see what you've tried
so far and please give a more detailed error description than just "seem
to break the select list". What happened? What was broken? In what way?

> I want the date/time in the drop down list to display
>as "Saturday, Aug 11 1:30 pm". It's stored in MySQL as "2008-08-11 1:30:00".
>The form works fine, but the formats aren't user friendly.


Sure, and with DATE_FORMAT() you can easily fix it without touching the
PHP code. But you would at least have to post your SQL query to see
where the problem might be.

Micha
Reply With Quote
  #3 (permalink)  
Old 07-29-2008, 09:25 PM
BROnstott
 
Posts: n/a
Re: Format date/time in dynamic drop down list

Thanks.

Here's the query:

SELECT game_date_time
FROM events
WHERE game_venue_id = game_venue_id_variable AND game_type_id =
game_type_id_variable AND game_date_time > NOW()
ORDER BY game_date_time

game_venue_id_variable and game_type_id_variable are session variables.

If I add DATE_FORMAT to the query like this:

SELECT DATE_FORMAT(game_date_time,'%W %b %e %r')
FROM events
WHERE game_venue_id = game_venue_id_variable AND game_type_id =
game_type_id_variable AND game_date_time > NOW()
ORDER BY game_date_time

I get nothing in the drop down list in the form. No errors that I can see,
just nothing to pick from. I have no clue why. It would seem that it should
work. If I don't put the DATE_FORMAT in there, it works fine.

Ideas?

Thanks in advance.



Reply With Quote
  #4 (permalink)  
Old 07-29-2008, 09:59 PM
Michael Fesser
 
Posts: n/a
Re: Format date/time in dynamic drop down list

..oO(BROnstott)

> Here's the query:
>
> SELECT game_date_time
> FROM events
> WHERE game_venue_id = game_venue_id_variable AND game_type_id =
>game_type_id_variable AND game_date_time > NOW()
> ORDER BY game_date_time
>
> game_venue_id_variable and game_type_id_variable are session variables.
>
> If I add DATE_FORMAT to the query like this:
>
> SELECT DATE_FORMAT(game_date_time,'%W %b %e %r')
> FROM events
> WHERE game_venue_id = game_venue_id_variable AND game_type_id =
>game_type_id_variable AND game_date_time > NOW()
> ORDER BY game_date_time
>
> I get nothing in the drop down list in the form. No errors that I can see,
>just nothing to pick from. I have no clue why. It would seem that it should
>work. If I don't put the DATE_FORMAT in there, it works fine.
>
> Ideas?


Yep. If you use any function or another kind of expression in the SELECT
part, you have to give the result a meaningful alias name, e.g.

SELECT DATE_FORMAT(game_date_time, '%W %b %e %r') AS formattedDateTime
FROM events
....

You can replace "formattedDateTime" with whatever name you want, except
for the original column name "game_date_time" - this would cause some
problems with the rest of the query.

Then simply use the chosen name in your PHP script:

<?php echo $row_rsGameDateTime['formattedDateTime']?>

Another note: You should check your local php.ini and make sure that the
error_reporting directive is set to E_ALL (or E_ALL|E_STRICT), and that
display_errors is enabled. Given your second query from above PHP should
have thrown an E_NOTICE error, because your script tried to access an
element in the result set which didn't exist.

HTH
Micha
Reply With Quote
  #5 (permalink)  
Old 08-15-2008, 02:29 AM
BROnstott
 
Posts: n/a
Re: Format date/time in dynamic drop down list

Thanks a million! Works like a champ!
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Software > Adobe Software > Dreamweaver


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:06 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
MPAA | Credit Card | Tents | Web Advertising | Car Loans



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114