PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Sep 23, 2019 3:19 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Tue Oct 15, 2013 4:16 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za
I'm creating code that will search multiple tables (at least 10) for dates matching the days on a calendar.

My two main concerns are 1) how to search multiple tables in a single sitting and 2) where in my calendar creating code to do the searching. I think i have point 2 covered, i will do the searching inside the code that creates the days ( below the dotted line in the following code )

Syntax: [ Download ] [ Hide ]
<?php
                                 if ($j <= $this->_numberOfDays) {
                                        // here ? search here ?
                                        // --------------------------------------
                                        // 1. the days of the month are printed here <------
                                        //    each day is checked inside this loop.
                                        // 2. i have the value of $j {value per day} which i can
                                        //    use to search against the database. If i hit a match, i
                                        //    need to make the day value a link.
                                        // 3. what will my search function look like?
                                        if ($j != $this->_currentDay) {
                                                echo '<td class="days">'. $j .'</td>';
                                                // or in here ? why in here ?
                                        }
                                        else {
                                                // or in here ? why in here ?
                                                echo '<td class="active">'. $j .'</td>';
                                        }
                                }
?>


Any ideas on how to go about the search would be welcome

thanks

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Tue Oct 15, 2013 3:26 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
...At least ten tables? What's the difference between them?

And what's the rest of your code? It'd be much more efficient to do all the searching at once before you start generating the calendar, rather than do ~30 searches for each day.


Top
 Profile  
 
PostPosted: Wed Oct 16, 2013 12:39 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Thu Oct 17, 2013 2:53 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za
I've come up with an idea of how to do the database searching prior to creating the calendar:

I'll have an array of days of the month and loop through it; each iteration will search against the database and if a match is found for the particular day another array is populated, something like 1 => 1 if there is an event on the first and 2 => 0 if there isn't.

Still not sure about the details but seems like an option imo

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Thu Oct 17, 2013 3:03 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
Wouldn't it make more sense to search the tables for all records with dates in the requested month -- then build the calendar with all that data?

_________________
(#10850)


Top
 Profile  
 
PostPosted: Thu Oct 17, 2013 4:14 pm 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Thu Oct 17, 2013 11:39 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
I think I would initialize an array with all the days in the month, then read in all records from the ten tables and assign them to the array as they are read (maybe adding their type). Then you have all the data and can just loop through the days array to generate the calendar.

Is there a way you can JOIN the tables and read them in one query to reduce the overhead of multiple queries?

_________________
(#10850)


Top
 Profile  
 
PostPosted: Sat Oct 19, 2013 1:06 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2794
Location: .za

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Sun Oct 20, 2013 11:12 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
Do the tables have similar schemas?

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Oct 21, 2013 5:56 am 
Offline
Forum Commoner

Joined: Thu Sep 19, 2013 2:53 am
Posts: 27
Try out with the below code, it has worked fine for me:

Syntax: [ Download ] [ Hide ]
$table=date,field name=date1,date2 , datatype=datetime
$sql="select date1 from date;
$result=mysql_query($sql) or die(mysql_error());
if($row=mysql_fetch_array($result))
   {
      $cr_date=date_create($row['date1']);
      $for_date=date_format($cr_date,'d-m-Y H:i:s');
   }
print $for_date;


Hope this helps.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group