Jump to content

Help Ending While Loop (correct placement)


thepresidentis

Recommended Posts

THIS IS A JOB CALENDER SCRIPT

 

I need help ending the while loop so that I can dislpay all the matching jobs from the database.

$day1 is a variable that contains job data from inside the while loop.

I found that if I

echo "$day1"
}    //END WHILE LOOP

I get 20 out of 20 jobs to display, BUT not in the calender ofcourse.

 

I also Find that if I

echo generate_calendar(date('Y', $time), date('n', $time), $days );    // ECHO THE CALENDER AND CALENDER DATA

}   //END OF THE WHILE LOOP

I only get 1 job to display but in the calendar.

 

There is an array that contains the information for each day it is here

$days = array( 
       
        1=>array($idlink,'linked-day',$day1), 
        2=>array($idlink,'linked-day',$day2), 
        3=>array($idlink,'linked-day',$day3), 
        4=>array($idlink,'linked-day',$day4), 
    ); 

 

In this array:

(1) would be the day

($idlink) would be a link to another page

('linked-day') defines what kind of link or text to display

($day1)  is text to display for the day example: the variable to display the jobs

 

I think there might be a problem with the while loop and the array :confused:

not sure though.

or maybe because the array is in a function and the variable for the job data is not?

i don't know

Here is my full script

//Dertimines Month and Year
$Mo = date ("m");
$Ye = date ("Y");
putenv("TZ=America/Los_Angeles");

// rows to return

//connect to database

mysql_connect()//(host, username, password)



//specify database 

mysql_select_db("Diablo") or die("Unable to select database"); //select which database we're using


// Building SQL Query  

//Display This Months Jobs

$query = "SELECT *
FROM `Customers` 

WHERE 
MONTH(DATE) = CONVERT( _utf8 '$Mo'
USING latin1 )
AND
YEAR(DATE) = CONVERT( _utf8 '$Ye'
USING latin1 )AND
`CANCELLED` != CONVERT( _utf8 'CANCELLED'
USING latin1 ) 
COLLATE latin1_swedish_ci
";



//determine if s has been passed to script, if not use 0




// Execute The query

$result = mysql_query($query) or die("Couldn't execute query: " . mysql_error());

// Get the number of rows returned by the DB.

$numrows=@mysql_num_rows($result);

?>
<style type="text/css">
table {
    width:1280px;
height:1024px;
    border:0px solid #888;    
    border-collapse:collapse;
}

td {
    width:200px;
height:350px;
    border-collpase:collpase;
    border:1px solid #888;
    text-align:right;
vertical-align: top;
    padding-right:5px;
}

.days2{
    background-color: #F1F3F5;

}



th {
    border-collpase:collpase;
    border:1px solid #888;
    background-color: #E9ECEF;
}

.actday{
    background-color: #c22;
    font-weight:bold;
}
</style>
<?php


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function generate_calendar($year, $month, $days = array(), $day_name_length = 3, $month_href = NULL, $first_day = 0, $pn = array()){ 
    $first_of_month = gmmktime(0,0,0,$month,1,$year); 
    #remember that mktime will automatically correct if invalid dates are entered 
    # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998 
    # this provides a built in "rounding" feature to generate_calendar() 

    $day_names = array(); #generate all the day names according to the current locale 
    for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday 
        $day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name 

    list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month)); 
    $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day 
    $title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names 

    #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03 
    @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable 
    if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> '; 
    if($n) $n = ' <span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>'; 
    $calendar = '<table class="calendar">'."\n". 
        '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>"; 

    if($day_name_length){ #if the day names should be shown ($day_name_length > 0) 
        #if day_name_length is >3, the full name of the day will be printed 
        foreach($day_names as $d) 
            $calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>'; 
        $calendar .= "</tr>\n<tr>"; 
    } 

    if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'"> </td>'; #initial 'empty' days 
    for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){ 
        if($weekday == 7){ 
            $weekday   = 0; #start a new week 
            $calendar .= "</tr>\n<tr>"; 
        } 
        if(isset($days[$day]) and is_array($days[$day])){ 
            @list($link, $classes, $content) = $days[$day]; 
            if(is_null($content))  $content  = $day; 
            $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>'). 
                ($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>'; 
        } 
        else $calendar .= "<td>$day</td>"; 
    } 
    if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days 

    return $calendar."</tr>\n</table>\n"; 
}

$time = time(); 
$today = date('j',$time); 


while ($row= mysql_fetch_array($result)) {
   $id = $row["id"];
    $timeneeded = $row["TIMENEEDED"];
  $title15 = $row["TIME"];
  $title = $row["FIRSTNAME"];
  $title1 = $row["LASTNAME"];
  $title2 = $row["ADDRESS"];
  $title3 = $row["CITY"];
  $title4 = $row["PHONE"];
  $title5 = $row["MOBILE"];
   $title6 = $row["EMAIL"];
   $title7 = $row["TYPEOFFIRE"];
   $title8 = $row["TYPEOFSERVICE"];
   $title9 = $row["OTHER"];
  $title10 = $row["PRICE"];
  $title11 = $row["REPAIRS"];
  $title12= $row["REPAIRSPRICE"];
  $title13 = $row["DATE"];
  $title14 = $row["EMPLOYEENUMBER"];
  $cancelled = $row["CANCELLED"];
  $userDate = $title13;
$dateArray = explode ("-" ,$userDate);
$americanFormat = $dateArray[1] . "-" . $dateArray[2] . "-" . $dateArray[0];

$dateArray2 = explode ("-" ,$userDate);
$month2 = $dateArray2[1];  
$dayX2 = $dateArray2[2];
$year2 = $dateArray2[0];
$weekday2 = date(" F  j,  Y", mktime(0,0,0,$month2,$day2,$year2));
$dayname = date ("l", mktime(0,0,0,$month2,$day2,$year2));

//formats time from database
if ($title15 == "1") 
{$newtime = "9:00 Am";}
elseif
($title15 == "2")
{$newtime = "10:30 Am";}
elseif
($title15 == "3")
{$newtime = "12:00 Pm";}
elseif
($title15 == "4")
{$newtime = "1:30 Pm";}
elseif
($title15 == "5")
{$newtime = "3:00 Pm";}
else
{$newtime = "";}

//formats a unique color for each truck number
if ($title14 == "1") 
{$newcolor =  'limegreen';}
elseif
($title14 == "2")
{$newcolor = 'RED';}
elseif
($title14 == "3")
{$newcolor = 'BLUE';}
elseif
($title14 == "4")
{$newcolor = 'grey';}
elseif
($title14 == "5")
{$newcolor =  'goldenrod';}
else
{$newcolor =  'goldenrod';}
                           //end format output color
//////////////////////////////////////////////////////////
                                  //begin check time for odd entry
if ($newtime == "") 
{$newtimeshow =  $title9;}
else
{$newtimeshow = $newtime;}
////////////////////////////////////////////////////////////
//Assign Variables to each day's jobs
if ($dayX2 == '01')
{$day1 =  "1 <BR><FONT color='$newcolor'> Truck: $title14 $newtimeshow,$title9 $timeneeded Hours $title3</FONT><BR>";}
elseif ($dayX2 =='02')
{$day2 =  "2 <BR><FONT color='$newcolor'> Truck: $title14 $newtimeshow,$title9 $timeneeded Hours $title3</FONT><BR>";}
elseif ($dayX2 =='03')
{$day3 =  "3 <BR><FONT color='$newcolor'> Truck: $title14 $newtimeshow,$title9 $timeneeded Hours $title3</FONT><BR>";}
elseif ($dayX2 =='04')
{$day4 =  "4 <BR><FONT color='$newcolor'> Truck: $title14 $newtimeshow,$title9 $timeneeded Hours $title3</FONT><BR>";}
///////////////etc...
$idlink = "id.php?id=$id";
// THIS IS THE ARRAY FOR EACH DAY
$days = array( 
       
        1=>array($idlink,'linked-day',$day1), 
        2=>array($idlink,'linked-day',$day2), 
        3=>array($idlink,'linked-day',$day3), 
        4=>array($idlink,'linked-day',$day4), 
    ); 

///END OF ARRAY (THERE WILL BE VALUES FOR EACH DAY OF THE MONTH HERE, I JUST SUMMARIZED IT FOR READING

$dork = generate_calendar(date('Y', $time), date('n', $time), $days );
echo $dork; // ECHO THE CALENDER AND CALENDER DATA

          }   //END OF THE WHILE LOOP
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.