PHP - Trying New Approach With Classes And Methods
So, I'm starting a new project and thought I would try a new approach at loading files and classes to process output. I think my logic is correct, but for some reason I'm getting a blank page. Basically instead of having seperate pages to output different functions and such, I store everything in one page. It's the same deal as the switch case approach, but it uses a foreach loop to cycle through the actions, classes, and functions which are stored in an array.
Here's my index.php file: Code: [Select] <?php require('config.php'); include('languages/english.php'); include('classes/Template.php'); $template = new Template; $viewPages = array( 'category' => array('classfile' => 'Category.php', 'classname' => 'category', 'functions' => array('create', 'delete', 'modify', 'merge')), 'questions' => array('classfile' => 'Question.php', 'classname' => 'Question', 'functions' => array('create', 'delete', 'modify', 'votegood', 'votebad')) ); $currentPage = $_REQUEST['action']; foreach($viewPages as $action => $settings){ if($currentPage == $action){ require(INCLUDE_ROOT.'/classes/'.$settings['classfile']); $class = new $settings['classname']; $function = $_REQUEST['do']; $class->$function(); $template->loadTemplate($settings['classname']->viewFile, $vars = array()); if($template->message == FALSE){ die($template->message); } } } ?> Here's the Template class file: Code: [Select] <?php class Template { var $file; var $vars; var $message; function loadTemplate($file, $vars){ if(empty($file) || empty($vars)){ $this->message = LANG_ERR_7; } else if($file = file_get_contents(INCLUDE_ROOT.'/'.$file)){ $this->message = LANG_ERR_7; } else { foreach($vars as $key => $val) $file = str_replace('{'.$key.'}', $val, $file); } $this->message = FALSE; return $file; } } ?> I tried visiting the category action(index.php?action=category;do=create). This is the classfile for that Code: [Select] <?php class category { var $id; var $title; var $description; var $uri; var $message = array(); var $vars = array(); var $viewFile = ''; function create(){ if($_POST['submit']){ //Review the user input and make ure everything is ok $messages = array(); if($this->title == FALSE){ $messages['title'] = LANG_ERR_1; } else if(strlen($this->title) > 30 || strlen($this->title < 5)){ $messages['title'] = LANG_ERR_2; } else if($this->description == FALSE){ $messages['description'] = LANG_ERR_3; } else if(strlen($this->description) > 400 || strlen($this->description) < 10){ $messages['description'] = LANG_ERR_4; } else { $messages = FALSE; } if($messages != FALSE){ $this->messages = $messages; $this->viewFile = INCLUDE_ROOT.'/template/index_body.tpl'; } else { $this->title = htmlentities($this->title); $this->title = stripslashes($this->title); $this->title = htmlspecialchars($this->title); $this->description = htmlentities($this->description); $this->description = htmlspecialchars($this->description); $this->description = nl2br($this->description); $query = " INSERT INTO categories (c_title, c_desc) VALUES('".$this->title."', '".$this->desscription."')"; if(mysql_query($query)){ $this->message['succes'] = LANG_ERR_5; } else { $this->message['fail'] = LANG_ERR_6; } $this->viewFile = INCLUDE_ROOT.'/template/message_body.tpl'; } } else { $this->viewFile = INCLUDE_ROOT.'/template/create_category.tpl'; } } } ?> Now if you look at the Category class, the template file it sets is the "category_create.tpl" file, which I haven't created yet. I'm expecting there to be an error associated with the template class and the file_get_contents function that calls the file, but like I said, I'm just getting a blank page. I've never tried this approach before, so I have no idea what's causing this. Any help would be greatly appreciated. Similar TutorialsHi, I am trying to get my head around classes, interfaces and methods for different animals
this is what I have so far: <?php interface animal { function walk(); function fly(); function swim(); } class monkey implements animal{ const interface1 = "I am from test class"; function noise() { echo "ooh ooh ah ah!"; } function walk() { echo "monkey is walking"; } function fly() { echo "monkey is Flying"; } function swim() { echo "monkey is Swimming"; } public function display() { echo monkey::interface1; echo PHP_EOL; } } class bear implements animal{ const interface1 = "I am from test class"; function noise() { echo "Grrr!"; } function walk() { echo "Bear is walking"; } function fly() { echo "Bear is Flying"; } function swim() { echo "Bear is Swimming"; } public function display() { echo bear::interface1; echo PHP_EOL; } } $Obj = new monkey(); $Obj->display(); $Obj1 = new bear(); $Obj1->display(); ?> I'm a bit stumped as animal interface not calling all functions?! please help hello, i have been following the php.net oop manual but im having a little trouble understanding something. on this page in the manual: http://uk3.php.net/manual/en/language.oop5.basic.php it shows this code and if i seperate it out i cant get it to echo the results i want. what am i doing wrong? i have added a little extra code . class Bear Code: [Select] class Bear { // define properties public $name; public $weight; public $age; public $sex; public $colour; // constructor public function __construct() { $this->name = "winny the poo"; $this->weight = 100; $this->age = 0; $this->sex = "male"; $this->colour = "brown"; } // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br/>"; $this->weight += $units; } public function run() { echo $this->name." is running... <br/>"; } public function kill() { echo $this->name." is killing prey... <br/>"; } public function sleep() { echo $this->name." is sleeping... <br/>"; } } class PolarBear Code: [Select] class PolarBear extends Bear { // constructor public function __construct() { parent::__construct(); $this->colour = "white"; $this->weight = 600; } function polarbar() { // Note: the next line will issue a warning if E_STRICT is enabled. Bear::bear(); } // define methods public function swim() { echo $this->name." is swimming... "; } } now if i try to get back the results i have trouble. this is fine Code: [Select] $bear = new Bear(); $bear->eat($units); $bear->eat(); $bear->run(); $bear->kill(); $bear->sleep(); that echos back Quote //THE BEAR winny the poo is eating 5 units of food... winny the poo is eating units of food... winny the poo is running... winny the poo is killing prey... winny the poo is sleeping... //THE POLAR BEAR winny the poo is eating 5 units of food... winny the poo is eating units of food... winny the poo is running... winny the poo is killing prey... winny the poo is sleeping... winny the poo is swimming... THAT FINE but how come i can echo out each of the properties? why do these ways not work? Code: [Select] Bear::eat($units); Bear::eat(); Bear::run(); Bear::kill(); Bear::sleep(); or Code: [Select] $bear = new Bear(); $bear->$name; $bear->$weight; $bear->$age; $bear->$sex; $bear->$colour; or Code: [Select] echo Bear::eat($units); echo Bear::eat(); echo Bear::run(); echo Bear::kill(); echo Bear::sleep(); or Code: [Select] $bear = new Bear(); echo $bear->$name; echo $bear->$weight; echo $bear->$age; echo $bear->$sex; echo $bear->$colour; and the same goes for PolarBear if i try and get back any of the properties on a page i get nothing ??? i even tried putting it in a loop and that didnt work Code: [Select] $bear = new Bear(); foreach ($bear as $bears){ echo $bears->$name; echo $bears->$weight; echo $bears->$age; echo $bears->$sex; echo $bears->$colour; } whats wrong. why cant i get any results from these ? thanks This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=345635.0 Currently I'm learning about objects and classes. I followed a tutorial about making a DB abstraction class (a mySQL select) and then I tried to adapt it and wrote a method to Insert a new name. However, then I had a problem: what if the value already exists in the DB? So I thought maybe I could write a method for that too, and hopefully this would be re-usable for other purposes. So I'm posting the code here and I hope someone could take a look at it, since I do not want to start any bad practices and start a habit of writing sloppy code. Would the code below be considered 'good code'? <?php // This file is called database.php class database { public $mysql; function __construct() { $this->mysql = new mysqli('localhost', 'root', 'password', 'db') or trigger_error('Database connection failed'); } /* Function to check whether value: $queriedName already exists inside table: $table and column: $column */ function findMatch($table, $column, $queriedName) { if ($result = $this->mysql->query("SELECT * FROM $table WHERE $column='$queriedName'")) { if (!$numberOfRows=$result->num_rows) { return false; } else { return true; } } } /* Function to select all records from table: $table */ function selectAll($table) { if ($result = $this->mysql->query("SELECT * FROM $table") ) { while($row=$result->fetch_object()) { $nameFields[]=$row->names; } return $nameFields; } } /* Function to insert a name: $newName into table: $table. Uses method finMatch to avoid doubles */ function insertName($table, $newName) { if ($this->findMatch($table, 'names', $newName)) { $result="Person already exists!"; return $result; } else { $result = $this->mysql->query("INSERT INTO $table(names) VALUES ('$newName')"); return $result; } // } } ?> Main page: // This file is called index.php require('database.php'); $newName='Mary Jane'; $result=$myDb->insertname('mytable', $newName); echo $result; I've been spending long hours learning about classes and their magic methods. I just came across a tutorial which showed a constructor like this:
class Device { //... public function __construct(Battery $battery, $name) { // $battery can only be a valid Battery object $this->battery = $battery; $this->name = $name; // connect to the network $this->connect(); } //... }the Battery part instantly caught my attention. Here had previously made a Battery class (and a more complete Device class) but the next thing he did really caught my interest: $device = new Device(new Battery(), 'iMagic'); // iMagic connected echo $device->name; // iMagicwhat the hell is going on here? Is this another way to include the methods and properties of one class into another class, in order words is this the same thing as: class Device extends BatteryI don't think so because this new Battery() thing looks more like its creating an object inside the Device object. Previously the only way I could to that was to type $battery = new Battery() inside one of my methods. But this looks like hes doing something different. Can anyone explain whats going on here? The whole tutorial is he http://code.tutsplus...-php--net-13085 in the main Device method he has a premade $battery variable to hold the Battery object. Sometimes I have multiple classes containing functions which I'd like to include in my main class. I can only extend one class, so I usually extent a class containing only properties, no methods. I still don't know what difference making that info class abstract is, I'd appreciate if anyone could tell me. Also I'd love to know what the point in static methods is. I've never used them because I've never seen the point. Is it just to make it easier to call the methods because you don't need to create an object instance to call them? Sorry for the extra questions, the first one is what I'm really wondering about. Well the title may seem a bit confusing, but heres an example: Code: [Select] <?php class User{ public $uid; public $username; protected $password; protected $email; public $usergroup; public $profile; public function __construct($id){ // constructor code inside } public function getemail(){ return $this->email; } public function getusergroup(){ return $this->usergroup; } public function getprofile(){ $this->profile = new UserProfile($this->uid); } } class UserProfile(){ protected $avatar; protected $bio; protected $gender; protected $favcolor; public function __construct($id){ // constructor code inside } public function formatavatar(){ // avatar formatting code inside } public function formatusername(){ // format username? } } ?> As you can see, the User class(an outer class) has a property called Profile, which can be instantiated as a UserProfile object(an inner class). The two objects have distinct functionalities, but there are times when the UserProfile object needs to access property and methods from the user object. I know its easy for outer class to access methods from inner class by using the single arrow access operator twice, but how about the other way around? Lets say from the above example the userprofile can format the username displayed to the screen by adding a sun to the left of the username if the usergroup is admin, a moon if the usergroup is mod, and nothing if its just a member. The usergroup property is stored in the outer class, and can be accessed with this $user->getusergroup() method only. I know I can always do the hard way by passing a user object to the method's argument, but is there an easier way for the inner class UserProfile to access properties/methods for outerclass User? If so, how can I achieve that? I am wanting to make a product list page with PHP. At the moment I using this code: Code: [Select] $query = "select * from products where category = 'Belts'"; $result = mysql_query($query); while($row=mysql_fetch_assoc($result)) { echo $row['name']; } The result is something like this: http://i51.tinypic.com/2w56ljq.png What I want is for them to be aligned like this: http://i53.tinypic.com/w811tz.png Eventually, I am also going to include an image with each product. How would I go about alignment? With CSS or PHP? Not sure how to describe what I'm trying to do here in the title, but here goes with what I am trying to accomplish. I've got a few hundred lines of code in total so far, so I'll try to keep it as short as I can. I've got an application that I am programming using classes for each module and right now I am coding the base classes that I need in order for it to run (database, errors, logging, etc). What I'm doing for my database class is I have a query factory and it extends the MySQLi class so I can process, clean and code the rest of my app faster. I also have another, unrelated class "Error", which will be used for processing errors I might come across. I'd rather do it this way instead of having to call trigger_error and error_log every time there is an error. I'd also not like to have to call a new instance of an object every time I need to use something from that class. Is there any way I can call a class within a class and return it as an object for all the methods within the class? I've tried the methods below, but no luck I've tried others, but I'm trying to keep it brief and get what I'm trying to do across. <?php class QueryFactory extends MySQLi { public $err = new error(); //Doesn't work. public $err = error(); //Nope. #This is the function that I need the $err object for. function set($fields, $newvals) { if ( is_array($fields) && is_array($newvals) ) { if ( count($fields) != count($newvals) ) { //Instead of below, I want to do something like $err->('Array lengths must match for method', 256, $islogged = 1); trigger_error('Array lengths must match for method', 256); } } } } The thing is, I have a "run.inc.php" which does include and create new objects for running just the basic app and if I try to redeclare the error class in query.class.php, it gives me an error saying I can't do that, but if i try to call $err from the page that has all the classes defined it throws an error saying that my method is undeclared. I'd like my error class be available to every other class I create so I can display and log errors as needed. Any suggestions or links to point me where I'd like to go? Hi everyone,
So I'm relatively new to OO PHP and moreover, OO PHP with MVC design pattern.
This may be a largeish post so please bear with me on this one!
So here is a scenario that I'd like to understand. There are likely multiple ways to go about this, but it'd be nice to see what is said.
I'll include what I think should be the solution here and hopefully i'll get some feedback about it.
Scenario:
A page needs to display a list of "parts" for a car. A database table already exists with these parts. The list of parts on the page need to be ordered by name on first load, but then can be re-ordered by users using a drop down list. They can also be filtered, and searched.
A page also exists to display a single car part.
What I think should be, and what i'm struggling with:
Model:
I will have a "part" object which represents an individual car part.
The part object will use a database abstraction layer. On "new Part()" will generate an empty object. ->Load( id ) will load an individual part.
Controller:
I do not know how I would implement this. I know it would contain methods to Filter(), Search() and Order() and that would directly access the Model.
View:
I am lost here too, I need to display a list of car parts, and on another page, a single car part. I understand I should use the same Model for both. However I do not see how I would list the parts.
Some Questions:
Should I have another "model" that is a list of the "Part" model called PaetListModel, or should "Part" be able to generate that list?
I clearly should have 2 views, one for singular part, one for list of parts. Should the view access the model to generate the list before using the data for output?
Should the controller be used in the view instead of the model to generate the initial list (or singular) on page load?
Should the filter functions in the controller reload the "PartsList" from wherever our list is stored?
I think the most important question for me though is:
How would YOU implement the above green scenario?
I would like to learn from peoples examples so I get an idea of what road to follow
I'm looking for some direction as I approach a new challenge. I have a table named friends_and_family and it contains name, email, and age fields. I'm planning a party and want to invite 10 of the people that are between 20 and 35 years old. The format I am considering would query the table and provide a list of those members that fit the age requirement. I would like to generate that result (which I should be capable of handling) so that each person listed has a checkbox next to their name. I imagine I will be creating a resultant form, so that I can then evaluate the result and select the checkboxes for those specific people that I want to invite. Upon submission, an email will be sent to the people with selected checkboxes. How should I approach this best? A for each loop? Implode an array? I'm not very good with AJAX, so I'm thinking along these lines.
Hello everyone, I am new to php and I need a confirmation if this is the correct approach for a code I wrote. Basically, I have a contacts.php page where I have a bootstrap table and a modal with some fields to add a new contact. I managed to write all the code, it works perfect but I want to know if this approach is ok. The application will be much more complex and I don;t want to start on the wrong foot here. I have 2 files: contacts.php and add_new_contact.php. First file, contacts.php: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <!-- ............ --> </head> <body> <!-- ............ here is the page layout--> <!-- Then I have my modal from bootstrap --> <div class="modal fade" id="addContact" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <form action = "add_new_contact.php" method="post"> <!-- .....content with all the inputs --> <button type="submit" class="btn btn-primary">Save to database</button> </form> </div> </body> </html> Now, in form action I am telling html to go to add_new_contact.php where I wrote the code for inserting all the values to the database. When doing this, it opens the page and it stays blank because there is no html there. So, in that php file I added a redirect code to the initial contacts.php. Here is the code: Second file: add_new_contact.php: <?php //all the code needed to insert the contact in the database header("Location: http//..../contacts.php"); exit(); ?> So, this works fine. But is this the best way to do it? Thank you. I currently use HTML strings within my PHP code to display output. And while it might not be best practice, I find it non-restrictive and I can easily add loops, manipulate variables, etc. within my display. However in the interest of having a cleaner code I'm thinking of separating the HTML, without having to use a Template engine like Smarty. I don't care much about replacement patterns to be honest, I don't mind some PHP code withing the HTML, however my biggest issue is loops and having to modify a variable within each loop. Say I have the following example code (Similar to what I'm using right now): Code: [Select] function student_output() { //Retrieve students from array $students_arr = students_info(); $selected_student = $_GET['selected_student']; $output = '<div id="students_container">'; $output .= '<div class="items_list">'; $i = 1; //Loop through students foreach($students_arr as $key=>$value) { if ($selected_student == $key) { $output .= '<div id="student_name_'.$i.'" class="selected">'.$value['student_name'].'</div>'; $output .= '<div id="student_img_'.$i.'" class="selected"><img src="'.$value['student_image'].'" /></div>'; } else { $output .= '<div id="student_name_'.$i.'">'.$value['student_name'].'</div>'; } $i++; } return $output; } What's the best way to represent this in HTML cleanly without having too much PHP code within? Hi Guys,
Greetings! Co - PHP freaks! I was hired by a company that requires me to create a purchase department program that will generate Quotations, P.O. , Receipt All of the database of this program will be stored to a server computer in a single office and all of the computer has a software that will access the data and should be able to generate a printable file like PDF or something. What is the best approach for this? any suggestions? I appreciate it in advance.
Cheers, MrGhaia I'm trying to process MS words doc in PHP. I found some samples which use COM applications for this but not working properly (I get only exceptions and no result) and I taught it's the version of word on my localhost or my OS so I tried them on with different windows OS and MS word. but same result, since it would be harder to make it work on remote server (the remote server needs to have MS word installed on) so I'm looking for different approach, what you think?? is there nay good one rather than COM applications? have you ever tried? is it possible to write code with other like ASP or java and combine it with PHP? every little piece of advice would be appropriated, thanks I have good knowledge of HTML, Css, Php and mysql, i would want to know, the best approach to creating an online dating site. any help hello dear community, i am currently wroking on a approach to parse some sites that contain datas on Foundations in Switzerland with some details like goals, contact-E-Mail and the like,,, See http://www.foundationfinder.ch/ which has a dataset of 790 foundations. All the data are free to use - with no limitations copyrights on it. I have tried it with PHP Simple HTML DOM Parser - but , i have seen that it is difficult to get all necessary data -that is needed to get it up and running. Who is wanting to jump in and help in creating this scraper/parser. I love to hear from you. Please help me - to get up to speed with this approach? regards Dilbertone All good with sending single dimensional form data to the server using application/x-www-form-urlencoded, and having PHP convert it into an array. Also, good with sending simple arrays using []. But then I find myself needing to send a deeper object to the server . For example, I have a form with three text inputs simpleFormName 1, 2, and 3 plus some deeper object. Array ( [simpleFormName1] => bla [simpleFormName2] => bla [simpleFormName3] => bla [deeperObject] => Array ( [0] => Array ( [prop1] => bla [prop2] => true [data] => Array ( [0] => Array ( [p1] => 321 [p2] => 123 ) [1] => Array ( [p1] => 121 [p2] => 423 ) [2] => Array ( [p1] => 221 [p2] => 133 ) ) ) [1] => Array ( [prop1] => blabla [prop2] => false [data] => Array ( [0] => Array ( [p1] => 222 [p2] => 443 ) [1] => Array ( [p1] => 321 [p2] => 213 ) [2] => Array ( [p1] => 111 [p2] => 421 ) ) ) ) )
I see at least four options: Come up with naming structure which "flattens" the data. I have used this approach in the past, but it quickly becomes difficult to manage and I don't want to do so. Not use PHP's POST and and instead use Content-Type: application/json and file_get_contents(php://input) and json_decode the entire request server side. Use PHP's POST and urlencoding but make deeperObject a string using JSON.stringify and json_decode this one field server side. Urlencode the entire object.simpleFormName1=bla&simpleFormName2=bla&simpleFormName3=bla&deeperObject%5B0%5D%5Bprop1%5D=bla&deeperObject%5B0%5D%5Bprop2%5D=true&deeperObject%5B0%5D%5Bdata%5D%5B0%5D%5Bp1%5D=321&deeperObject%5B0%5D%5Bdata%5D%5B0%5D%5Bp2%5D=123&deeperObject%5B0%5D%5Bdata%5D%5B1%5D%5Bp1%5D=121&deeperObject%5B0%5D%5Bdata%5D%5B1%5D%5Bp2%5D=423&deeperObject%5B0%5D%5Bdata%5D%5B2%5D%5Bp1%5D=221&deeperObject%5B0%5D%5Bdata%5D%5B2%5D%5Bp2%5D=133&deeperObject%5B1%5D%5Bprop1%5D=blabla&deeperObject%5B1%5D%5Bprop2%5D=false&deeperObject%5B1%5D%5Bdata%5D%5B0%5D%5Bp1%5D=222&deeperObject%5B1%5D%5Bdata%5D%5B0%5D%5Bp2%5D=443&deeperObject%5B1%5D%5Bdata%5D%5B1%5D%5Bp1%5D=321&deeperObject%5B1%5D%5Bdata%5D%5B1%5D%5Bp2%5D=213&deeperObject%5B1%5D%5Bdata%5D%5B2%5D%5Bp1%5D=111&deeperObject%5B1%5D%5Bdata%5D%5B2%5D%5Bp2%5D=421 Any recommendations how to best implement? If you recommend using urlencoding for simple forms, but some other approach for more complex data, what criteria do you use to transition from one approach to another? Thanks good evening dear Community, Well first of all: felize Navidad - I wanna wish you a Merry Christmas!! Today i'm trying to debug a little DOMDocument object in PHP. Ideally it'd be nice if I could get DOMDocument to output in a array-like format, to store the data in a database! My example: head over to the url - see the example: the target http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=8880 I investigated the Sourcecode: I want to filter out the data that that is in the following class <div class="floatbox"> See the sourcecode: <span class="grey"> <span style="font-size:x-small;">></span></span> <a class="navLink" href="http://dms-schule.bildung.hessen.de/suchen/index.html" title="Suchformulare zum hessischen schulischen Bildungssystem">suche</a> </div> </div> <!-- begin of text --> <h3>Siegfried-Pickert Schule</h3> <div class="floatbox"> See my approach: Here is the solution return the labels and values in a formatted array ready for input to mysql! <?php $dom = new DOMDocument(); @$dom->loadHTMLFile('http://dms-schule.bildung.hessen.de/suchen/suche_schul_db.html?show_school=8880'); $divElement = $dom->getElementById('floatbox'); $innerHTML= ''; $children = $divElement->childNodes; foreach ($children as $child) { $innerHTML = $child->ownerDocument->saveXML( $child ); $doc = new DOMDocument(); $doc->loadHTML($innerHTML); //$divElementNew = $dom->getElementsByTagName('td'); $divElementNew = $dom->getElementsByTagname('td'); /*** the array to return ***/ $out = array(); foreach ($divElementNew as $item) { /*** add node value to the out array ***/ $out[] = $item->nodeValue; } echo '<pre>'; print_r($out); echo '</pre>'; } well Duhh: this outputs lot of garbage. The code spits out a lot of html anyway. What can i do to get a more cleaned up code!? What is wrong with the idea of using this attribute: $dom->getElementById('floatbox'); any idea!? any and all help will greatly appreciated. season-greetings db1 I am trying to wrap my head around the best approach to accomplish this.
I am trying to come up with a random schedule for a full 24 hour day with random time periods ranges including breaks.
The only constants will be the minimum time and maximum time of the events and the minimum and maximum time of the breaks between each event.
for example
There are three teams
Team A
Team B
Team C
Each event will last either a minimum of 7 minutes to a maximum of 38 minutes
The breaks will last a minimum of 30 seconds to a maximum of 5 minutes.
so the events need to be generated randomly with a break period following each event and the timelines are different for each team
with the current event time left going to a timer on the page
I think I have the part to generate the random blocks figured out by using
<!DOCTYPE html> <html> <body> <?php function eventRange($min, $max, $blocks) { $events = range($min, $max); shuffle($events); return array_slice($events, 0, $blocks); } function breakRange($min, $max, $blocks) { $breaks = range($min, $max, 0.1); shuffle($breaks); return array_slice($breaks, 0, $blocks); } echo"<pre>"; print_r( eventRange(7,38,32) ); echo"</pre>"; echo"<pre>"; print_r( breakRange(.5,5,32) ); echo"</pre>"; ?> </body> </html>bur is there a way to make it fill a full 24 hour period and then a way to determine which block to display based on the current time when either team is viewing the page. Sounds totally confusing to me as I try to explain it so I hope what Im asking makes sense. Thanks for any guidance.. hey guys im wdondering if there's a magic method which works like
__GET()but allows you to put a parameter in...thank you <?php class test { public function run() { $this->object->('string'); // __get with parameter? } public function __get($value) { return $this->{$value} } } ?> |