[SOLVED]Request help with better dbcalltoreduceloading time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wHiTeHaT
Forum Newbie
Posts: 15
Joined: Thu Nov 17, 2005 2:48 pm

[SOLVED]Request help with better dbcalltoreduceloading time

Post by wHiTeHaT »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello @all

I'm working on a calendar for wherein the dates act as products.
So when i click on a date was is setted as an event , it will be added to the shoppingcart basket.
This part i have working , except the problem is that it load all dates out of the database @once.
I dont now how to make a better call to the database.
It should give me only the results of the current month's entrys.
i post below my full code for this page , and i really would apreciate the help.
please keep in mind that i will also have to add in short time a extra value that it go look up to what main/aditional product this date belongs to.
This part ive not made yet:
a live example can seen here:
http://www.inteladd.com/modules.php?nam ... e=products

Code: Select all

define('INDEX_FILE', true);
require_once("mainfile.php");
require_once("source/activecalendar.php");

$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
global $db;

$myurl= 'modules.php?name=Fly_to_Basket&file=products'; // the links url is this page
$yearID=false; // GET variable for the year (set in Active Calendar Class), init false to display current year
$monthID=false; // GET variable for the month (set in Active Calendar Class), init false to display current month
$dayID=false; // GET variable for the day (set in Active Calendar Class), init false to display current day
extract($_GET);
$products_id = $_GET['products_id']; 
$products_id = preg_replace("/[^\d]/si","",$products_id); 

$cal=new activeCalendar($yearID,$monthID,$dayID);

$eventID="event"; // sets the name of the generated HTML class on the event day (css layout)
$result = $db->sql_query("SELECT UNIX_TIMESTAMP(calendar_date) AS calendar_date, calendar_id, calendar_price, did FROM calendar");
	
OpenTable();
while ($row = $db->sql_fetchrow($result, MYSQL_BOTH)){
$products_id = $row["calendar_id"];

$calendar_price = $row['calendar_price'];
$mysqlDay=date("j",$row["calendar_date"]); // makes a day out of the database date
$mysqlMonth=date("n",$row["calendar_date"]); // makes a month out of the database date
$mysqlYear=date("Y",$row["calendar_date"]); // makes a year out of the database date
$mysqlContent= $row["did"]; // gets the event content
//$mysqlLink=$row[$tblLink]; // gets the event link
$mysqlLink = "#\" onclick=\"addToBasket('$products_id');return false;"; // the name of your MySQL Table Link Field
//$cal->setEvent($mysqlYear,$mysqlMonth,$mysqlDay,$eventID); // set the event, if you want the whole day to be an event
$cal->setEventContent($mysqlYear,$mysqlMonth,$mysqlDay,$mysqlContent,$mysqlLink); // set the event content and link
$cal->enableMonthNav($myurl);

?>
<script type="text/javascript" src="modules/Fly_to_Basket/js/ajax.js"></script>
<script type="text/javascript" src="modules/Fly_to_Basket/js/fly_to_basket.js"></script>
<?php

		

echo"<div id=\"slidingProduct_$products_id\">";
	
	
echo "</div>";

}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Last edited by wHiTeHaT on Fri Oct 13, 2006 1:42 pm, edited 1 time in total.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

white hat,

try this

Code: Select all

SELECT UNIX_TIMESTAMP(calendar_date) AS calendar_date, calendar_id, calendar_price, did FROM calendar WHERE MONTH(calendar_date) = MONTH(CURDATE()) 
for more information on the MONTH CURDATE see The MYSQL Manual[/syntax]
wHiTeHaT
Forum Newbie
Posts: 15
Joined: Thu Nov 17, 2005 2:48 pm

Post by wHiTeHaT »

lol... Ironic kendall

i was just trying again and i think i found the solution... however yours do excact same as my solution.
Infact it is couse of 2 scenario.

my trick was the folowing:

Code: Select all

$result = $db->sql_query("SELECT UNIX_TIMESTAMP(calendar_date) AS calendar_date, calendar_id, calendar_price, did FROM calendar WHERE MONTH(calendar_date)='$monthID'");
However this only work when navigate << or >> true the months couse it is posted within the url.

Then imade this on top:

Code: Select all

$now = time();
$j = date("j", $now);
$m = date("n");
$y = date("Y", $now);
And changed:

Code: Select all

$result = $db->sql_query("SELECT UNIX_TIMESTAMP(calendar_date) AS calendar_date, calendar_id, calendar_price, did FROM calendar WHERE MONTH(calendar_date)='$m'");
Now i need a trick in php to check if $m = empty ... ifso take $monthID
lol and i dunno how to do that either... at thi smoment... i have to search first some other codes to see if i can use it.
Anyway thank you for helping me. :wink:
Last edited by wHiTeHaT on Fri Oct 13, 2006 1:39 pm, edited 2 times in total.
wHiTeHaT
Forum Newbie
Posts: 15
Joined: Thu Nov 17, 2005 2:48 pm

Post by wHiTeHaT »

8)


i have it

Code: Select all

$yearID=date("Y"); // current year
$monthID=date("n"); // current month
$dayID=date("j");
if (isset($_GET['yearID'])) $yearID=$_GET['yearID'];
if (isset($_GET['monthID'])) $monthID=$_GET['monthID'];
if (isset($_GET['dayID'])) $dayID=$_GET['dayID'];
$now = time();
$j = date("j", $now);
$m = date("n", $now);
$y = date("Y", $now);

$result = $db->sql_query("SELECT UNIX_TIMESTAMP(calendar_date) AS calendar_date, calendar_id, calendar_price, did FROM calendar WHERE MONTH(calendar_date)='$monthID'");
Post Reply