Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-26-2012, 03:03 PM   PM User | #1
lonepalm
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lonepalm is an unknown quantity at this point
Need help gathering info from MySQL tables using PHP

Hello All. I found this forum after looking for some resources to help. Let me preface by saying I have little to no knowledge of PHP, but a little SQL experience (although it is more Oracle SQL than MySQL, which my website uses). I realize these forums might be aimed more towards people with knowledge on what they are talking about but just need clarification, but I'm hoping my issue is easy enough for someone to quickly chime in and give me a hand. Thanks!

So, what I'm trying to do is essentially use PHP code to connect to a database to pretty much display an hours of operation type module on my wordpress site (I have a plugin to enable a widget to use PHP code).

Basics:

-I'd like the widget, or PHP code, to update itself based on the current date/time so when a visitor would look at the site, it will be up to date based on their date/time, or if easier, the server date/time without me having to manually enter the information every day.

-I will need to display multiple operating hours based on, say, department or area, which are stored in the database. There are some special cases where if a boolean value in the table is set to 1, then it will also need to display the secondary operating hours as well as the primary, which are both in the same day but do not overlap.

So, in essence, in vague terms, I'd like it to look like this:

Today's Hours: (current date based on date/time)
[area1] : [open] - [close]
[if boolean = 1 display secondary hours label and hours, if 0 don't display] : [open] - [close]
[area2] : [open] - [close]
[if boolean = 1 display secondary hours label and hours, if 0 don't display] : [open] - [close]
etc, etc, etc (up to 9 or 10 areas).

Anything in [] are values in a database. Area1, area2, etc names are in table1. The [open] and [close] and [date] are in table2 with the [areaID] as a foreign key.


I apologize for the vagueness, and if it would help to be more clear, please let me know. I sincerely appreciate any help (or code!) that anyone can provide. I plan on reading some books on PHP to try and learn it since I'd like to be doing some more custom stuff for my site, but I'd like to have this particular widget sooner, rather than later, so any help is truly appreciated. Thanks!
lonepalm is offline   Reply With Quote
Old 12-26-2012, 07:43 PM   PM User | #2
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Here are a few places to start:

For MySQL w/ PHP, use the Improved Extension (mysqli): http://php.net/manual/en/class.mysqli.php

PHP has really nice date() and time() functions - they revolve around a UNIX Timestamp, I recommend getting familular with that (it's pretty basic)

http://php.net/manual/en/function.date.php
http://php.net/manual/en/function.time.php

You will need to code a connector to your MySQL database, query for your data (http://php.net/manual/en/mysqli.query.php) and then perform a simple loop to display your data and manipulate it in anyway you desire

I won't code anything for you, because that's not how you learn, however, I will advise you on your work and point you in the right direction
TFlan is offline   Reply With Quote
Old 01-02-2013, 05:29 PM   PM User | #3
lonepalm
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
lonepalm is an unknown quantity at this point
Quote:
Originally Posted by TFlan View Post
Here are a few places to start:

For MySQL w/ PHP, use the Improved Extension (mysqli): http://php.net/manual/en/class.mysqli.php

PHP has really nice date() and time() functions - they revolve around a UNIX Timestamp, I recommend getting familular with that (it's pretty basic)

http://php.net/manual/en/function.date.php
http://php.net/manual/en/function.time.php

You will need to code a connector to your MySQL database, query for your data (http://php.net/manual/en/mysqli.query.php) and then perform a simple loop to display your data and manipulate it in anyway you desire

I won't code anything for you, because that's not how you learn, however, I will advise you on your work and point you in the right direction
Thank you. I will try to read through your information you provided and try to find the time to post up some rough drafts so you can advise. Thanks!
lonepalm is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:13 PM.


Advertisement
Log in to turn off these ads.