Help needed

I am trying to design an events calender, I have created a page to input hte data and everything works fine. I am having trouble on the viewing page getting the data from the data base. Here is the code

[php]

<?php $db_addr = "somehost"; $db_name = "somedatabase"; $db_user = "someuser"; $db_pass = "somepass"; $table_name = "main"; $table_name = "times"; header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Cache-Control: post-check=0, pre-check=0"); $months = array( "01" => "January", "02" => "February", "03" => "March", "04" => "April", "05" => "May", "06" => "June", "07" => "July", "08" => "August", "09" => "September", "10" => "October", "11" => "November", "12" => "December" ); if (!$dbh = @mysql_connect($db_addr, $db_user, $db_pass)): die ("Connection to the data base server could not be made."); endif; // MySQL data base auswaele if (!$dbdat = @mysql_select_db($db_name, $dbh)): die ("Database could not be selected."); endif; function table_exists($table) { GLOBAL $db_name; $result = mysql_list_tables ($db_name); if (!$result) {echo "Examination of the tables could not be accomplished.
";} else { while($row = mysql_fetch_row($result)){ if ($row[0] == $table) return true; } } return false; } function check_date($d, $m, $Y){ if (date("m-d-Y", mktime(0, 0, 0, $m, $d, $Y)) == "$m-$d-$Y") return true; return false; } function daysinmonth($month, $year) { if(checkdate($month, 31, $year)) return 31; if(checkdate($month, 30, $year)) return 30; if(checkdate($month, 29, $year)) return 29; if(checkdate($month, 28, $year)) return 28; return 0; } function weeksinmonth($month, $year){ $firstDay = array ("01", $month, $year); $lastDay = array (daysinmonth($month, $year), $month, $year); $tst1 = mktime (1, 0, 0, $firstDay[1], $firstDay[0], $firstDay[2]); $tst2 = mktime (1, 0, 0, $lastDay[1], $lastDay[0], $lastDay[2]); $wa = date("W", $tst1); $we = date("W", $tst2); if ($wa == 53) $wa = 1; $weeks = $we - $wa; return array($weeks, $wa, $we); } function get_time ($tst){ Global $timestring; $lok = date($timestring, $tst); return (!empty ($tst)) ? $lok : ""; } $plan_nr = (empty($_GET['plan_nr'])) ? 1 : $_GET['plan_nr']; $year = (empty($_GET['year'])) ? date("Y", time()) : $_GET['year']; $month = (empty($_GET['month'])) ? date("m", time()) : $_GET['month']; $week_days = array(0, 1, 2, 3, 4, 5, 6); $tarr = array(); if (isset($_GET['plan_nr'])) $gnr = "&plan_nr=".$_GET['plan_nr']; $cur_month = date("m", time()); $y = date("Y", time()); $yk = substr ($y, 2, 2); $month1 = $months['01']; $month2 = $months['02']; $month3 = $months['03']; $month4 = $months['04']; $month5 = $months['05']; $month6 = $months['06']; $month7 = $months['07']; $month8 = $months['08']; $month9 = $months['09']; $month10 = $months['10']; $month11 = $months['11']; $month12 = $months['12']; $error = false; $alloc_month = array(); $query = "SELECT * FROM $main_table_name WHERE plan_nr = '$plan_nr' AND YEAR(alloc) = '$year' AND MONTH(alloc) = '$month'"; if ($result = mysql_query($query)) { while ($row = mysql_fetch_array ($result)){ $alloc_month[] = $row["alloc"]; } } asort ($alloc_month); list ($weeks, $first, $last) = weeksinmonth($month, $year); $week_table = ""; $days = 0; $days = daysinmonth($month, $year); $tm = date("w", mktime(1, 0, 0, $month, 1, $year)); for ($i = 0; $i <= $weeks; $i++){ $week_table .= ""; foreach ($week_days AS $k => $v){ $fwd = ($tm - 1 >= 0) ? $tm - 1 : 6; if ($i == 0) if ($fwd == $v) $day = 1; if (strlen($day) == 1) $vday = "0".$day; else $vday = $day; if ($vday == "00") $vday = "-"; $timest = mktime(0, 0, 0, $month, $day, $year); (check_date($dey, $mon_wn, $year)) ? "$year-$mon_wn-$dey" : ""; $v_dates = date ("Y-m-d", $timest - 86400); $n_dates = date ("Y-m-d", $timest + 86400); if(in_array($dates, $alloc_month) && $vday != "-"){ $arrive = $depart = false; $vtd = ""; if (!in_array($v_dates, $alloc_month)) { $vtd = "background="arrive.jpg""; $arrive = true; } if (!in_array($n_dates, $alloc_month)){ $vtd = "background="depart.jpg""; $depart = true; } if (!$arrive && !$depart){ $vtd = "background="booked.jpg""; } }else{ $vtd = "background="free.jpg""; } $week_table .= "".$vday.""; if ($day > 0 && $day < $days) $day++; else $day = 0; } $week_table .= ""; } ?>

[/php]

The page views like this

http://ww2.apartmentloscristianos.me.uk/cal/view.php

I can get results for an individual month but not all the months. I can get results if I use a tabular display but It doesnt look right within the site

Does anybody have any ideas

I am not sure what you are trying to do or what isn’t working?

Could try to clarify the situation and the problem(s) you are having?

Thanks.

sorry i didn’t reply, but had the same prob.

I am trying to pull dates from a database and show them on a webpage

Its a 12 month availability calender for my website but I’ve got myself in a mess with it

wher u got into the mess? in your first post i see a script selecting one month. but in that link there are 12 month showen. all of that dosn’t make a lot of sence to me and i just don’t know where to start (i’m sorry: i don’t have the time to go thru every line of code to find an error, this would take as long as rewriting the script).

try echoing you variables, (print_r() for arrays). this may help u to find the point where it is going wrong

Or break up your code into sections, with some clearly visible marker and a comment that explains what the following code does. That way, you can make it clear for yourself what exactly is going on where and would easy the debugging/troubleshooting heaps.

Gave up on it, Going with another format instead. Thanks for all your suggestions though

Sponsor our Newsletter | Privacy Policy | Terms of Service