PHP - Best Approach Guidance
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.
Similar TutorialsIt's always these seemingly simple tasks that become challenges. I got a good handle on how to watermark some photos (thanks to respondents to my previous post) and developed a script that calls a function that uses imagettftext() Essentially, I can upload multiple images and watermark them before they reach their destination folder. Good stuff. Now, I got this crazy idea of watermarking them with a sequence number, so that if I grab 12 images, each will be labeled with it's sequence number (rather than a standard text watermark). I placed $count++ in my script, and then used $count as my $watermark both inside imagettftext and as a variable. It didn't work. The closest I got was after placing $count++ inside a watermark function, but. of course, that merely labeled each photo with a "1" (bc each call of the function was a new iteration. Can someone please offer some direction here. Thanks.
I have created a script that will upload and reminder images. Now, I want to replace the timestamp with a number so that each image is listed sequentially with more easily recognized values (1,2,3,etc). My concern is the effect this could have if several uploads were coincidentally started simultaneously. I doubt the script (or directory) would allow duplicate names to be rendered, so would I lose files because of overwriting?
If 3 uploads of 10 images each were all started at exactly midnight what could go wrong? How can I best resolve the risk and ensure that I get 30 complete files sequentially numbered? I am trying to set up a class for my database connection. I have it working one way, this is a completely new method I am trying to learn. I have a file called MyClasses.php and in that file I did this. (I am following a not very well done tutorial) Code: [Select] class MySQLDatabase { private $connection; function __construct(){ $this->open_connection(); } public function open_connection(){ $this->connection = new MySQLi('localhost','MyDatabase','password','billpay') or die($mysql->error); } } $database = new MySQLDatabase(); then in my index page where I want to begin by doing a query on the database, I did this Code: [Select] <?php include MyClasses.php ?> $result = $database->query("SELECT * FROM names") or die($mysql->error); but that gives me this error Fatal error: Call to undefined method MySQLDatabase::query() in C:\wamp\www\BillPay\index.php I can't figure out how to get past it. Hi guys, I need some help from you pro's please with converting code from a TPL template file to PHP. My client has payment gateway scripts in an ecommerce site that he wants to offer to other merchants. The code currently is in numerous TPL files (currently being used in Opencart). What is involved in converting to plain ol' PHP? Do I need the TPL files at all? Can I rename the TPL extension to PHP as it looks like they contain PHP code?? Example of one of the TPL's is below: <form action="<?php echo $action; ?>" method="post" id="checkout"> <input type="hidden" name="instId" value="<?php echo $merchant; ?>" /> <input type="hidden" name="cartId" value="<?php echo $order_id; ?>" /> <input type="hidden" name="amount" value="<?php echo $amount; ?>" /> <input type="hidden" name="currency" value="<?php echo $currency; ?>" /> <input type="hidden" name="desc" value="<?php echo $description; ?>" /> <input type="hidden" name="name" value="<?php echo $name; ?>" /> <input type="hidden" name="address" value="<?php echo $address; ?>" /> <input type="hidden" name="postcode" value="<?php echo $postcode; ?>" /> <input type="hidden" name="country" value="<?php echo $country; ?>" /> <input type="hidden" name="tel" value="<?php echo $telephone; ?>" /> <input type="hidden" name="email" value="<?php echo $email; ?>" /> <input type="hidden" name="testMode" value="<?php echo $test; ?>" /> </form> <div class="buttons"> <table> <tr> <td align="left"><a onclick="location = '<?php echo $back; ?>'" class="button"><span><?php echo $button_back; ?></span></a></td> <td align="right"><a onclick="$('#checkout').submit();" class="button"><span><?php echo $button_confirm; ?></span></a></td> </tr> </table> </div> I also have 3 PHP files as well, which look like (example): <?php class ControllerPaymentOnlineVoucher extends Controller { protected function index() { $this->data['button_confirm'] = $this->language->get('button_confirm'); $this->data['button_back'] = $this->language->get('button_back'); $this->load->model('checkout/order'); $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); $this->load->library('encryption'); $this->data['action'] = 'https://www.domain-removed.com/purchaseAndRedeem.php'; $this->data['merchant'] = $this->config->get('onlineVoucher_merchant'); $this->data['order_id'] = $order_info['order_id']; $this->data['amount'] = $order_info['total']; $this->data['currency'] = $order_info['currency']; $this->data['description'] = $this->config->get('config_store') . ' - #' . $order_info['order_id']; $this->data['name'] = $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname']; if (!$order_info['payment_address_2']) { $this->data['address'] = $order_info['payment_address_1'] . ', ' . $order_info['payment_city'] . ', ' . $order_info['payment_zone']; } else { $this->data['address'] = $order_info['payment_address_1'] . ', ' . $order_info['payment_address_2'] . ', ' . $order_info['payment_city'] . ', ' . $order_info['payment_zone']; } $this->data['postcode'] = $order_info['payment_postcode']; $payment_address = $this->customer->getAddress($this->session->data['payment_address_id']); $this->data['country'] = $payment_address['iso_code_2']; $this->data['telephone'] = $order_info['telephone']; $this->data['email'] = $order_info['email']; $this->data['test'] = $this->config->get('onlineVoucher_test'); $this->data['back'] = $this->url->https('checkout/payment'); $this->id = 'payment'; $this->template = $this->config->get('config_template') . 'payment/onlineVoucher.tpl'; $this->render(); } public function callback() { if (isset($this->request->post['callbackPW']) && ($this->request->post['callbackPW'] == $this->config->get('onlineVoucher_password'))) { $this->language->load('payment/onlineVoucher'); $this->data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); if (!isset($this->request->server['HTTPS']) || ($this->request->server['HTTPS'] != 'on')) { $this->data['base'] = HTTP_SERVER; } else { $this->data['base'] = HTTPS_SERVER; } $this->data['charset'] = $this->language->get('charset'); $this->data['language'] = $this->language->get('code'); $this->data['direction'] = $this->language->get('direction'); $this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); $this->data['text_response'] = $this->language->get('text_response'); $this->data['text_success'] = $this->language->get('text_success'); $this->data['text_success_wait'] = sprintf($this->language->get('text_success_wait'), $this->url->https('checkout/success')); $this->data['text_failure'] = $this->language->get('text_failure'); $this->data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), $this->url->https('checkout/payment')); $this->data['button_continue'] = $this->language->get('button_continue'); if (isset($this->request->post['transStatus']) && $this->request->post['transStatus'] == 'Y') { $this->load->model('checkout/order'); $this->model_checkout_order->confirm($this->request->post['cartId'], $this->config->get('onlineVoucher_order_status_id')); $message = ''; if (isset($this->request->post['transId'])) { $message .= 'transId: ' . $this->request->post['transId'] . "\n"; } if (isset($this->request->post['transStatus'])) { $message .= 'transStatus: ' . $this->request->post['transStatus'] . "\n"; } if (isset($this->request->post['countryMatch'])) { $message .= 'countryMatch: ' . $this->request->post['countryMatch'] . "\n"; } if (isset($this->request->post['AVS'])) { $message .= 'AVS: ' . $this->request->post['AVS'] . "\n"; } if (isset($this->request->post['rawAuthCode'])) { $message .= 'rawAuthCode: ' . $this->request->post['rawAuthCode'] . "\n"; } if (isset($this->request->post['authMode'])) { $message .= 'authMode: ' . $this->request->post['authMode'] . "\n"; } if (isset($this->request->post['rawAuthMessage'])) { $message .= 'rawAuthMessage: ' . $this->request->post['rawAuthMessage'] . "\n"; } if (isset($this->request->post['wafMerchMessage'])) { $message .= 'wafMerchMessage: ' . $this->request->post['wafMerchMessage'] . "\n"; } $this->model_checkout_order->update($this->request->post['cartId'], $this->config->get('onlineVoucher_order_status_id'), $message, FALSE); $this->data['continue'] = $this->url->https('checkout/success'); $this->template = $this->config->get('config_template') . 'payment/onlineVoucher_success.tpl'; $this->render(); } else { $this->data['continue'] = $this->url->https('checkout/payment'); $this->template = $this->config->get('config_template') . 'payment/onlineVoucher_failure.tpl'; $this->render(); } } } } ?> Any guidance would be highly appreciated... Phil Hello: I am very new to PHP. I have done a few basic feedback forms, but that's it. I have done Classic ASP for years, and am trying to switch over to PHP. I wanted to see what it would take to make a basic CMS that would allow users to update page content from an admin panel. Very much like the attached .JPG demo. Is there existing code available like what I'm trying to do? I can post the ASP version code if it will help. I assume it would need a database, but I have only used DNS-less connections with Access - not anything PHP related. I know the site is hosted on justhost.com, and justhost.com uses unix servers. Any assistance would be appreciated! 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? This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=314445.0 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. 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
Helo - Total newbie here, so please keep that in mind. I'd really appreciate some wisdom from someone here as to how you would improve this form: <?php $email = $_POST['email']; $message = $_REQUEST['message']; $message = $_POST['date']; $message .= $_POST['location']; $message .= $_POST ['comments']; mail( "testing@gmail.com, 5602346789@metropcs.com", "General Inquiry", $message, "From: $email" ); header( "Location: thankyou.html" ); ?> *******************************html****************************** <HEAD><title>Hi</title<HEAD><BODY BGCOLOR="lightgray"><br><br><center><br><br><form method="post" action="sendmail2.php"><table cellspacing="5" cellpadding="5" border="0"> <tr> <td valign="top"><font face="arial"> <strong>Contact email:</strong><br> </td> <td valign="top"><font face="arial"> <input type="text" name="email" size="50" value="" /> </td> </tr><tr><td valign="top"><font face="arial"> <strong>Date:</strong> </td> <td valign="top"><font face="arial"> <input type="text" name="date" size="50" value="" /> </td> </tr> <tr><td valign="top"><font face="arial"> <strong>location:</strong><br> </td> <td valign="top"> <input type="text" name="location" size="50" value="" /> </td> </tr> <tr> <td valign="top"><font face="arial"> <strong>Comments:</strong><br><font color="black"> </td> <td valign="top"> <textarea name="comments" rows="6" cols="40"></textarea> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value=" Submit Form " /> </td> </tr> </table> </form></center></body> 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? 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. 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 Gday, I'm trying to add a contact form on my site using a PHP script I downloaded from the web. I have tweaked the script, but I have never used PHP before and haven't got the time to learn it yet. Could someone please help me to get this working, I have added a subject drop down field that I would like to add validation to force the user to choose one, and I'd like the subject they choose to appear in the subject field of the resulting email. Once the PHP script has run and the email has been sent I'd like the text at the bottom to appear on the original page. At the moment when i click submit it just goes to the php page and shows three lines of the error message text. Here is the relevant code: This form is placed within a static html page: Code: [Select] <form name="contactform" method="post" action="send_form_email.php" style="text-align:left;"> <label for="first_name">First name <span class="red">*</span></label> <input name="first_name" type="text" value="please enter your first name" size="30" maxlength="75" onclick="document.contactform.first_name.value='';" /> <br/> <label for="last_name">Last name <span class="red">*</span></label> <input name="last_name" type="text" value="please enter your last name" size="30" maxlength="75" onclick="document.contactform.last_name.value='';" /> <br/> <label for="email" style="margin-right:32px;">Email <span class="red">*</span></label> <input name="email" type="text" value="please enter your email address" size="30" maxlength="75" onclick="document.contactform.email.value='';" /> <br/> <label for="phone_number" style="margin-right:34px;">Phone</label> <input name="phone_number" type="text" value="please enter your phone number" size="30" maxlength="75" onclick="document.contactform.phone_number.value='';" /> <br/> <label for="email_subject" style="margin-right:19px;">Subject <span class="red">*</span></label> <select name="email_subject" style="margin-bottom:10px;"> <option value="Choose one">Choose one</option> <option value="Lost my password">Lost my password</option> <option value="Gardening advice">Gardening advice</option> <option value="Order status">Order status</option> <option value="Web feedback">Web feedback</option> <option value="Customer Service">Customer Service</option> <option value="Product feedback">Product feedback</option> <option value="Other">Other</option> </select> <br/> <label for="comments">Queries/Comments <span class="red">*</span></label> <textarea rows="10" cols="50" wrap="virtual" name="comments" onclick="document.contactform.comments.value='';" style="margin-bottom:5px;">Please type your query or comments here</textarea> <input type="submit" value="Submit" /> </form> and here is the seperate php script that is used: <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "johnc@diggers.com.au"; $email_subject = $_REQUEST['email_subject']; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['email_subject']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $telephone = $_POST['email_subject']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"; if(!eregi($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "^[a-z .'-]+$"; if(!eregi($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!eregi($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } $string_exp = "^[0-9 .-]+$"; if(!eregi($string_exp,$telephone)) { $error_message .= 'The Telephone Number you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch within 72 hours of the next working day. <? } ?> Any help on how to get this going would be greatly appreciated, thanks 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 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 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.. |