Jump to content

array into variable


dubc07

Recommended Posts

$time = array( "html"     => "<b>$name</b><br>Solo",  //
               "style"    => "background-color: $color", // use style property to change the background color
               "interval" => $intrv // set the interval for 2hrs
			);

Link to comment
https://forums.phpfreaks.com/topic/115088-array-into-variable/#findComment-591843
Share on other sites

I have been working on this script for quite some time im trying to build a online schedule for aircraft rental,
But I'm having no luck grabbing user's from mysql database and applying them to the output of the script.
working with arrays is not one of my specialty's Here's the script.
If someone could figure how to grab data from mysql and apply it to this THAT WOULD BE AWESOME.

<?php

require_once('connect22database.php');






$options = array( 
		"row_interval" => 30, // set the schedule to display a row for every /2hr
		"start_time" => 700, // schedule start time  (10am)
		"end_time" => 2200,   // schedule end time (10pm)

		"title_style" => "font-family: verdana; font-size: 14pt;", // css style for schedule title
		"time_style" => "font-family: verdana; font-size: 8pt;",  // css style for the time cells
		"dayheader_style" => "font-family: verdana; font-size: 10pt;", // css style for the day header cells

		// default css style for the class cells. Eachs tyle can be overridden using the "style" property of each class
		// see schedule.inc.php for details.
		"class_globalstyle" => "background-color: #EBEBEB; font-family: verdana; font-size: 8pt; text-align: center;", 
);



	// if no row interval set or is zero, use 30mins
	if ( intval($options["row_interval"]) == 0 ) $options["row_interval"] = 30;	

	// define start time as 8am if not set
	if ( ! isset($options["start_time"]) ) {
		$options["start_time"] = 700;
	}
	else {
		// change to the nearest row interval hour down.
		$time_hour = ($options["start_time"] - $options["start_time"] % 100) / 100; 
		$time_min = $options["start_time"] % 100;

		$time_totalmins = $time_hour * 60 + $time_min;

		if ( $time_totalmins % $options["row_interval"] > 0) $time_totalmins = $time_totalmins - $time_totalmins % $options["row_interval"];
		$options["start_time"] = ($time_totalmins - $time_totalmins % 60) / 60 * 100 + $time_totalmins % 60;

	}


	// define end time as 10pm if not set
	if ( ! isset($options["end_time"]) ) {
		$options["end_time"] = 2200;
	}
	else {
		// change to the nearest row interval hour down.
		$time_hour = ($options["end_time"] - $options["end_time"] % 100) / 100; 
		$time_min = $options["end_time"] % 100;

		$time_totalmins = $time_hour * 60 + $time_min;

		if ( $time_totalmins % $options["row_interval"] > 0) $time_totalmins = $time_totalmins - $time_totalmins % $options["row_interval"];
		$options["end_time"] = ($time_totalmins - $time_totalmins % 60) / 60 * 100 + $time_totalmins % 60;

	}

	$days_arr = array( "air1", "air2", "air3", "air4", "instructor", "instructor");
	$days_norow = array(0, 0, 0, 0, 0, 0, 0 );


	$html = "<table width=\"100%\" bgcolor=\"#FFFFFF\" cellspacing=\"2\" cellpadding=\"0\">\n";

	// output title if set in $options.
	if ( isset($options["title"]) ) {
		$cell_style = "background-color: #FFCC00; color: #0099CC;"; // default title style 
			$cell_style .= $options["title_style"];

		$html .= "	<tr>\n		<th colspan=\"8\" style=\"$cell_style\">".$options["title"]."</th>\n	</tr>\n";
	}

	$cell_style = "background-color: #0099CC; color: #FFFFFF;"; // default day header style
	$cell_style .= $options["dayheader_style"];

	$html .= "	<tr style=\"$cell_style\">\n		<th> </th>\n";
	foreach ($days_arr as $day){
		$html .= "		<th>$day</th>\n";
	}
	$html .= "	</tr>\n";

	$cur_time = $options["start_time"];
	while ($cur_time < $options["end_time"]) {
		$format_time = date("g:ia", strtotime(substr($cur_time, 0, strlen($cur_time) - 2).":".substr($cur_time, -2, 2)));

		$cell_style = "background-color: #FF9900; color: #FFFFFF;"; // default time cell style

		$cell_style .= $options["time_style"];			

		$html .= "	<tr bgcolor=\"#ffffff\">\n		<td align=\"right\" width=\"2%\" style=\"$cell_style\"><b>$format_time</b></td>\n";

		for ($cur_day = 0; $cur_day < 6; $cur_day++) {

			// if flag is set not to print any row for the next
			// row (since a class spans more than one row), then
			// continue.
			if ($days_norow[$cur_day] > 0) {
				$days_norow[$cur_day]--;
				continue;
			}
		$cell_style2 = "bgcolor=\"#EBEBEB"; // default time cell style
		//select which database you want to edit
mysql_select_db("x?whoknows"); 



   //display all the news
   $result = mysql_query("select * from rentme order by plane"); 
   
   //run the while loop that grabs all the news scripts
   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID of the news
      $name=$r["name"];//take out the title
      $time=$r["time"];//take out the id
  $plane=$r["plane"];
  $intrv=$r["intrv"];
  $color=$r["color"];
  $image='<img src="'."$pics".'" width="90" hight="90">';//image poster 

$timess = array( "html"     => "<b>$name</b><br>Solo",  //
               "style"    => "background-color: $color", // use style property to change the background color
               "interval" => $intrv // set the interval for 2hrs
);

$times =array( $time.$timess
			),;



$planes ='2';
$elaps = '240';
$pname = "$name";
$type = 'Solo';
$time = '800';

$plane =array($plane => 
		// Adds a class at 12pm (1200 hours)
		$times 

			);

}
$classes_arr =$name=$r["name"];

$classes_arr = $plane;
				 // check if there is a class during this day/time
			if ( isset($classes_arr[$cur_day][$cur_time]) ) {

					$class_interval = intval($classes_arr[$cur_day][$cur_time]["interval"]);
					if ( $class_interval == 0 ) $class_interval = 60; // default interval is 60mins

					// round to nearest interval
					$class_span = intval($class_interval / $options["row_interval"]);

					// flag that for the next $class_span rows, we should not print a cell
					$days_norow[$cur_day] += $class_span - 1;		

				    if ( isset($classes_arr[$cur_day][$cur_time]["style"]) )
						$cell_style = $options["class_globalstyle"]."; ".$classes_arr[$cur_day][$cur_time]["style"];
					else
						$cell_style = $options["class_globalstyle"];

					$html .= "		<td width=\"14%\" rowspan=\"$class_span\" style=\"$cell_style\">".$classes_arr[$cur_day][$cur_time]["html"]."</td>\n";

			}		
			else {
					$html .= "		<td width=\"14%\ style=\"$cell_style2\"> </td>\n";			


			}


		}


		$html .= "	</tr>\n";

		$cur_time += $options["row_interval"]; // increment to next row interval
		if ($cur_time % 100 >= 60) $cur_time = $cur_time - $cur_time % 100 + 100;
	};



	$html .= "</table>\n";

	echo $html;





?> 

Link to comment
https://forums.phpfreaks.com/topic/115088-array-into-variable/#findComment-591867
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.