Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
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 )
<?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
...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.
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
Christopher wrote: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?
indeed, my problem is how to use the results that i find to construct the calendar; if there is an event on a specific day, that day will be click-able. So my thoughts with the previous comment was that i would search the tables for events on day X and if any matches are found i'd create an array, giving it a value of 1 and 0 for days with no events. From the i'd know which days on the calendar would need to be links to a page containing all the events.
“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
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?