PHP - Tricky Php Timecode Issue For Radio Site - Willing To Pay For Solution
Similar Tutorialshii I have made some code that works out the difference between two timecodes. IE Time 1 Time 2 Time2-Time1 1330613232 - 1330613545 = 313 Im wanting to express the difference in terms of hours. 313 as a time code is 00:06:49 but I want it to show 0.12 hours. how would I achieve this? x I am doing some practice with classes. MY class below echoes out input and radio fields based on the instantiation of the Form class (the code below is working!), but I am trying to resolve how to get my form radio fields so they are not in between every other form field as they are supposed to be next to eachother. If you run the below, you will see what I mean. And also is my approach at all sensible? I am only doing this for learning experience, so any advice please. <?php class Form { private $fields = array(); private $radios = array(); private $actionValue; private $submit = "Submit Form"; private $Nradios = 0; private $Nfields = 0; function __construct($actionValue, $submit) { $this->actionValue = $actionValue; $this->submit = $submit; } function displayForm() { echo "<form action='{$this->actionValue}' method='post'>\n\n"; for ($j = 1, $i = 1; $j <= sizeof($this->fields), $i <= sizeof($this->radios); $j++, $i++) { echo "<p>\n<label>{$this->fields[$j-1]['label']} : </label>\n"; echo "<input type='text' name='{$this->fields[$j-1]['name']}'>\n</p>\n\n"; echo "<p>\n<label>{$this->radios[$i-1]['rlabel']} : </label>\n"; echo "\n<input type='radio' name='{$this->radios[$i-1]['rname']}' value='{$this->radios[$i-1]['rvalue']}'>\n</p>\n\n"; } echo "\n\n<input type='submit' value='{$this->submit}'>\n</form>"; } function addField($name, $label) { $this->fields[$this->Nfields]['name'] = $name; $this->fields[$this->Nfields]['label'] = $label; $this->Nfields = $this->Nfields + 1; } function addRadio($rname, $rvalue, $rlabel) { $this->radios[$this->Nradios]['rname'] = $rname; $this->radios[$this->Nradios]['rvalue'] = $rvalue; $this->radios[$this->Nradios]['rlabel'] = $rlabel; $this->Nradios = $this->Nradios + 1; } } ?> <?php $contact_form = new Form("process.php", "Submit Data >>"); $contact_form->addField("first_name", "First Name"); $contact_form->addField("last_name", "Last Name"); $contact_form->addRadio("gender", "male", "Male"); $contact_form->addRadio("gender", "femail", "Female"); $contact_form->displayForm(); ?> Hi all, I'm looking for some help in parsing an XML file from geocaching.com. It's pretty far beyond me as I've never tried parsing XML like using PHP before (although I'm OK at PHP in a general sense). Ideally I'm looking to be able to query every element in this file (attached, renamed to .txt - was originally .gpx) so that I can do stuff with it. I don't need to update the file, just read it and create a UI from the contents. Should I use SimpleXMLElement, xml_parser or something else? The structure of the file isn't something I've encountered before because of the <groundspeak:log> formatted elements. I'm only used to relatively simple XML files with the colon-separate bits. Can anyone help? Thanks! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358972.0 I'm really fond of your coding and need some help too I'm also trying to make a tree and save it in an xml file such that parent_id of one node is inserted in as pages key to the father node.By running this query $sql = "Select * from category order by parent_id ASC"; I'm getting the following result. Array ( => Array ( [category_id] => 2 [parent_id] => 0 [category_name] => Clothes ) [1] => Array ( [category_id] => 5 [parent_id] => 1 [category_name] => T-shirts ) [2] => Array ( [category_id] => 6 [parent_id] => 1 [category_name] => Cotton-Shirts ) [3] => Array ( [category_id] => 1 [parent_id] => 2 [category_name] => Upper ) [4] => Array ( [category_id] => 4 [parent_id] => 2 [category_name] => Lower ) [5] => Array ( [category_id] => 3 [parent_id] => 4 [category_name] => Pants ) ) My code is as follows but not executing correctly function searchTree($arr,$node,$i){ if(!in_array($node['parent_id'],$arr[$i])) { $stmt = '<pages_'.$i.'>'; $stmt .=$node; $stmt .='</pages_'.$i.'>'; return $stmt;} else{ //print_r($returnTree); print_r ($arr[$i]);//['category_id']; $returnTree = ($arr[$i]['category_id']==$node['parent_id'])? searchTree($arr,$node,$i++): searchTree($arr,'',$i++); } } $i=0; foreach($links as $link){ $myArr = searchTree($links,$link,$i);} The result should be as follows: <page_1> <label>Clothes</label> <uri>#</uri> <pages> <page_1_1> <label>Upper</label> <uri>#</uri> <pages> <label>T-Shirt</label> <uri>#</uri> <page_1_1> <page_1_1_1> <label>Short Sleaves</label> <uri>#</uri> </page_1_1_1> <page_1_1_2><label>Long Sleaves</label><uri>#</uri> </page_1_1_2></page_1_1></page_1> <page_1_2> <label>Lower</label> <uri>#</uri> <pages>....</page_1_2> Hopefully you can unsderstand this problem. Please help me. My friend has this problem, it needs a solution. I have no PHP experience, I don't know how to work with MD5 hash. A programming unit was compulsory on her course, but she completely fails on it. So let's be unethical and help her survive it. thanks in advance ===================== You are the website administrator for a website that requires a low level password for entry. The previous owner of the website forget to code in a password recovery feature and as such you now have to recover the passwords for a number of users of the website. You do have acess to the website databse BUT you are NOT allowed to manually change the passswords for users in the database as those passwords are heavily used in defining what permissions a user of the website has. e.g Moderators for the website forum all have a password begining with the lower case letter "m" in lower case. ALL letters are lowercase. Passwords were allocated to all users and the method of choice was to create a password which was built on two parts - a lowercase letter "m" and a number between 1 and 10000. An md5 hash was then created to form a 32 digit string. e.g the user with password "m1234" is represented in the database as the md5 hash: 77c12394ef7d4f23a8fa07d87309afd9 You have five users who need their orignal password. You know that the passwords all start with the letter "m". You decide that the simplest thing to do is to write some PHP code that uses a while loop to increment through the numbers 0 to 10000, concatenate that number with the "m" and then compare the md5 hash to that you recovered from the database. If the two hashes are the same then you have "cracked" the password. This technique is known as a "brute force" method of cracking passwords. You have a number of hashes to "crack" and you must enter the unique password into the answer box for each. As a starting point, the following PHP snippet will produce all of the lowercase letters: ___________________________________ Code: [Select] for ($i=97; $i<=122; $i++){ $x = chr($i); echo $x; } ?> Hi, I am having trouble with some GIF, PNG images the error I am receiving these errors imagecreatefromgif() [function.imagecreatefromgif]: '/tmp/phpNAhLPI' is not a valid GIF and a similar one for PNG Is there a solution to this? and How can I hide these errors? So they never display to the user and Instead I echo a user friendly error. Please note again this is happening with some GIF and PNGs not all of them. Appreciate any help and thanks in advance! SQL error2.Cannot add or update a child row: a foreign key constraint fails (`facility`.`fapplication`, CONSTRAINT `fapplication_ibfk_1` FOREIGN KEY (`fstaffid`) REFERENCES `fstaff` (`fstaffid`)) is there any solution for this problem cause my deadline is next week aaaaa... Ok I have a form that will include some text boxes and two sliders where numbers can be selected. When a user clicks submit I want it to take them to a solutions page based on what numbers they have selected. I'm finding it hard to explain what I'm trying to do so heres an example of what I would like. http://www.cleardebt.co.uk/#help It will be a form like that which links to a solution. If someone could please tell me what I need to do or have a tutorial of something similar it would be a great help for me to start. hey guys i wrote an quick and dirty anagram solver for a challenge on hts which works great but i am more interested on feedback of how I could have written it better / more efficiently. anyone have there own version of writing this? thanks Code: [Select] $scramwords = array("htssboe","rtefcelh","vteevl","edsiyn","awloddno","dtey1d","kuedci","seellhy","sernin","acianro"); $unscramwords = array(); $filename = '../wordlist.txt'; // loop through scrambled words foreach($scramwords as $scramword) { // open the file if($fh = fopen($filename,'r')) do { // read line $line = fgets($fh); // see if line and scrambled word are same length if((strlen(trim($line))) == (strlen(trim($scramword)))) { //if they are the same length split the line into and array and the scrambled word into an array $l = array(); for($i=0;$i<strlen(trim($line));$i++){ $l[$i] = substr(trim($line),$i,1); } $s = array(); for($i=0;$i<strlen(trim($scramword));$i++){ $s[$i] = substr(trim($scramword),$i,1); } $errors = 0; // see if the arrays are different $chk = array_diff($l,$s); if(!empty($chk)){ $errors = 1; } // see if arrays are different in reverse order $chk2 = array_diff($s,$l); if(!empty($chk2)){ $errors = 1; } // found scrambled word if(!$errors) { array_push($unscramwords,$line); } } }while(!feof($fh)); fclose($fh); } // print out comma seperated un scrambled words echo implode(",",$unscramwords); This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349561.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=356124.0 Hey guys/Gals ok, so if you want code let me know but in essence just a quick question to an unforseen issue. Were creating a virutal hacking simulation (for those who have been following me) and we just finised with the crack.php that compares the passwordcracker to the target users Systemkey (the piece that protects the target's pc from lower level attacks) if the passwordcracker is larger than the systemkey or equal to it, it will start the crack procress (that is simply a progress bar, then forward to userhome.php) issue were having right now is when the user attempts to crack but isn't high enough to do so it gives a message saying your software isn't high enough... ISSUE: if at this point I just go and type in userhome.php it connects me without having to crack it.. there is a session set in place that makes sure users are logged in the whole time but can't figure out how I can stop this from allowing access without a successful crack first.... any ideas would be greatly appreciated Thanks; desjardins, jeff Ok, well basically i'm not sure if this can be done or not. Basically I have a IM type bar for my website similar to facebook. It's from CometChat.com. Anyway the place to edit the links to all the modules for the bar are done in the config.php file. What I'm trying to do is put a link for users to click to go directly to their profile on the site. To do this i get the user's ID, and reference it to the mysql database, get the nickname, pass it to a varaiable and plug the variable into the url in the config file. The problem I'm having is when I run ANY mysql commands in the config file it kills the CometChat script from showing at all on the site. I'm not sure why since the whole config file is in php... so i don't see how mysql statements would keep the script from showing. Another Idea I thought about was running the mysql statements in another php file and somehow get that variable from a php code in the config.php file.. but i'm not really sure what code will run the mysql file and return the variable i need. Any help is greatly appreciated. Hi guys, I have a simple INSERT code. It does not throw any errors and all seems ok but the data is just not appearing in the DB. I've spent ages looking over it but perhaps a 2nd set of eyes could help? Thanks! Code: [Select] $con = mysql_connect("localhost","posturep",""); $tablename = 'product'; if (!$con) { die('Could not connect: ' . mysql_error()); } //Form data sent $product_name = $_POST['product_name']; $product_active = $_POST['product_active']; $product_cat = $_POST['product_cat']; $product_desc = $_POST['product_desc']; $prod_inoutdoor = $_POST['prod_inoutdoor']; $prod_stackable = $_POST['prod_stackable']; $prod_discounted = $_POST['prod_discounted']; echo $product_name; $sql = "INSERT INTO $tablename (name) VALUES ($product_name)"; mysql_query($sql); echo "<p>Product Saved!</p>"; echo $sql; mysql_close($con); I use a script for sharing links. Everything works ok, but checking for valid images can take a long time. First through CURL method I parse certain tags (for description and title) then I use the following script to find images from the submited link: Code: [Select] $dom = new domDocument; @$dom->loadHTML('<?xml encoding="UTF-8">' . substr($content,0,35000)); $dom->preserveWhiteSpace = false; $images = $dom->getElementsByTagName('img'); It sometimes happens that the images have not not a good path(depending on whether the link is permanent or not) and then use the getimagesize function that works well. But it can be very slow ...sometimes it takes 15-30 seconds. Without function getimagesize process takes a few seconds. Is there a better (faster) method to check whether the image is valid or not? Hi all. I am currently trying to build a site that will allow users to manage a self build house project. This is my first php MySQL project but I am getting to grips with it ok. I am currently building this for my own benefit at the moment as I am about to undertake a self build. I have a few questions to put to you guys. This is where I am at the moment I have a database table named materials which contains a list of materials , quantities, unit of measurement, id. My site has a user control panel that has separate forms for each stage of the build where the user enters the quantities of the materials, and the data is displayed as an array for each stage. So, heres question 1. I want to take the data and use it to generate a form which will be completed by several merchants.... so it will display similar to the array but will be a form with a text box for price where the merchant will insert a price. i.e <?php mysql_connect ("localhost", "test", "test") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); // query $query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); // results while ($row = mysql_fetch_array($query)) { echo "<br />" .$row ['id']. " " .$row ['material']. " " .$row['quantity']. " " .$row['unit']. "<br />";} echo mysql_error(); ?> I want to add a text input box form which will allow the merchant to add a price to each item that is added to the array. so there the merchant will be able to give me a price for all the items in my list. Heres where I get stuck.... as I am constantly adding to the list I have no fixed amount of items so the form for the merchants needs to be built dynamically, ie each time I add a new material, I want the merchants form to get a new input. I am not very good at describing my problems but I am hoping that someone can help me out from the information given. Thats the first question. i like to get issues sorted in small bites. the second is the next big bite, I want to send the form above to several merchants, so I intend to have a user database with a user for each merchant, and link the tables so that each merchant can provide a price for each material, ideally the form would highlight the materials that have not had a price yet. I'm looking for advice on the best method of doing this basically but if I can get the first question sorted that would be great.. I have the test site local but can upload it it to the server if it will help you see what im trying to do. Any help that anyone can give will be greatly appreciated. i want to make a forum that nobody can fill that through any software automatically i make this one with java script authentications but some one also make a break of this and and he fill this software only in one click with automatic way this one which i make http://www.ebs-ads.com/advertising/forms.php?id=4&name=Abel any better solutions using php or any other function that users must have to post every input field separately manually ..if yes Please suggest me thanks Hi all, I would like to ask you if somebody could have a better idea to build this function. The current one is working, but I feel this built a bit in an amateur manner. Feel free to add your ideas so we can learn more about PHP and how to deal with arrays.
I have an array: $arrayVideoSpecs = Array( Array( 'aspect' => '4:3', 'density' => '442368', 'resolution' => '768x576' ), Array( 'aspect' => '4:3', 'density' => '307200', 'resolution' => '640x480' ), Array( 'aspect' => '16:9', 'density' => '2073600', 'resolution' => '1920x1080' ), Array( 'aspect' => '16:9', 'density' => '121600', 'resolution' => '1280x720' ) );
and I want an array as output grouped by video aspect ratio where the key is the pixel density and the value is the video resolution, namely like that for aspect ratio 16:9 ... Array ( [2073600] => 1920x1080 [121600] => 1280x720 )
Then I coded this function which is working but seems amateur ... function groupAndExtractByAspect($array, $groupBy, $aspect, $density, $resolution) { $groupByAspect = Array(); foreach ($array as $value) { $groupByAspect[$value[$aspect]][] = Array($value[$density], $value[$resolution]); } $arrayClean = Array(); foreach ($groupByAspect as $key => $value) { if ($key == $groupBy) { $arrayClean[$key] = $value; } } foreach ($arrayClean as $aspectGroup) { $arrayOutput = Array(); for ($i = 0; $i <= count($aspectGroup); $i++) { $densityIsValid = false; $resolutionIsValid = false; if (!empty($arrayClean[$groupBy][$i][0])) { $density = $arrayClean[$groupBy][$i][0]; $densityIsValid = true; } if (!empty($arrayClean[$groupBy][$i][1])) { $resolution = $arrayClean[$groupBy][$i][1]; $resolutionIsValid = true; } if (($densityIsValid === true) && ($resolutionIsValid === true)) { $arrayOutput[$density] = $resolution; } } } return $arrayOutput; }
The usage is as follow ... $showArray = groupAndExtractByAspect($arrayVideoSpecs, '16:9', 'aspect', 'density', 'resolution'); echo '<pre>'; print_r($showArray); echo '</pre>';
Thank you very much for your ideas! Mapg |