PHP - Quick (probably Simple) Question About Coding Practice
Hey guys,
Why exactly do people use multiplication when calculating time? Like when setting cookies, timeouts or something that requires second-based definitions. For example, some do: Code: [Select] $thirty_days = time()+60*60*24*30; As opposed to what I do: Code: [Select] $thirty_days = time()+2592000; Why do they do that? Does it help them calculate it without a calculator? Make it easier to manage/adjust in the future? Personal preference? These are the only possible explanations I can think of. This has been bugging me for a while...am I doing something wrong? Similar TutorialsWhat is the best practice for using site-wide constants in a class? E.g. COMPANY_NAME is set in a config file and used on many pages. How would it be best to use this in a class. I'm guessing just calling COMPANY_NAME anywhere in the class would not be considered best practice. Thanks. I have a quick question to ask, as i cant see it in their docs. Maybe you can help me. I am using http://simplehtmldom.sourceforge.net/ Right, i have written a Simple HTML Dom script to collect data from this page, as an example: http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.html Script executed by running a cron job on this file (which generates the XML): http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.php The data is collected, and written to this file in XML file: http://www.visualdesign.ie/_dev/myscraper/simplehtmldom/dev-env/scraping/daily/daily.xml Thats is fine, and the script essentially scrapes the entire page, with no conditional IF's for any sections. A sample of my code for one segment is below: http://pastebin.com/JLb8f92N What i would like to do now, and i am hoping you could help out is... Scrap this same page, but produce seperate XML files, based on the date. So if you view that page, i want to scrape the data in the table Saturday 4th February 2012 and produce XML for for that day only. The i want to scrape the data in the section for Sunday 5th February 2012, and another for Tuesday 7th February 2012. I think its self explanatory. The table date sections are separated by this HTML element: bg color = " #CCCCCC " But bare in mind that the table rows on each date section will change when the site is updated, and there may be additional or less football game records. Anyway, i would appreciate any help you can show me, on how to place in any conditionals in the code, and only scrape the date sections needed. Separate script files would be fine if it was needed. Many thanks for your time, Darren. Hi I am looking to develop a public facing website and would like some good practice info on php, what you should and shouldnt do and which way to do things, e.g. for security and efficiency, etc. I have read through the PHP security guide from the PHP Security Consortium and was really good, does any one have any more info like this regarding PHP and general good practice Thank you I don't really have an issue with my script... I simply want to know if it is a bad practice to create a script that recurses through your root directory and zips up everything into one large zip file... I am creating a backup deal for my site and my site is rather large... Is this considered bad practice? Hi I need someone to fix a bug I have and to "speed up" the loading of the image by having the firs x number of images load first then loading more after they finish.
The bug should be easy to fix as I have a working copy of the page minus the change I made. The problem is since I updated to code the other part wont work (
contact me for more details and let me know you how much you would charge.
Thanks,
.
How do i display an image from my directory?!? :S I don't mean to be lazy and just ask people on here, I have researched it online but can't seem to find a quick simple answer. Thanks People!! hey guys i have a script that creates a cookie named "MyLoginPage" now everything works well the cookie is saved and it keeps the user logged in The Question ok so im wanting to create a link that will delete the cookie so when the user clicks the link it will delete the cookie is this possible?? if so, how?? many thanks how to open a site with curl that has frames ? when ive tried it gives "your broswer does not support frames" ... hi. when i get into some function manual and there is a note says. Quote This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. . is that meaning that after 5.3.0 version this function will not be supported? thanks , Mor. Does storing multiple values in 1 database field with a varchar let's say set at 150, all separated by "|'s" so I don't have to create a field name for each one is it better performance wise or no? (storing 6-7 different |'s that will be outputted with a array ofc) ? Is there a way to only output the first, say, 30 words of a variable? I have a way to do it in mind, but seems like it's messy and not practical. Any suggestions? E.g: WITHOUT LIMIT: Welcome to my store. Would you like to buy something? We have really good noodles and fishes in doodle pools. WITH LIMIT: Welcome to my store. Would you like... Sort of like a short preview. code <?php //storecodefound.php v1.0 //purpose is to store the http refer and the code associated with the site to a db to be collected and verified by submitcode.php $code = $_GET['code']; $site = $_SERVER['HTTP_HOST']; //check to see if the code already present $connect = mysql_connect("localhost","root","") or die (mysql_error()); $check = mysql_query("SELECT code FROM hunter.codes WHERE code='$code'") or die (mysql_error()); $row = mysql_num_rows($check); echo "result of \$row is ".$row; echo "<br />"; if ($row = 0) { //insert into db cause it's not there mysql_query("INSERT INTO hunter.codes (id, code, site) VALUES ('','$code','$site')") or die (mysql_error()); } else { //echo it's already here echo "Code already found on server!"; } ?> my question is the result of $row is infact 0 and the if statement says if $row is 0 to insert into db and instead it's given me the code is already found? hey! I have a site where I want to use multiple issets at the same time, like if I have four buttons and four issets: if(isset($_POST['one'])) { echo '<div class="example_box">one</div>'; } if(isset($_POST['two'])) { echo '<div class="example_box">two</div>'; } if(isset($_POST['three'])) { echo '<div class="example_box">three</div>'; } if(isset($_POST['four'])) { echo '<div class="example_box">four</div>'; } but for some reason it seems like only one isset can be activate at a time, is there any way to work this out or something :s? I've tried some variants of elseif stuff and such, but yeah, I'm pretty new at this stuff I am starting to learn PDO by re-writing one of my existing scripts. Do I still need to validate $_GET or does PDO do the work for me? Currently I am using: Code: [Select] $id = $_GET['id']; $sth = $dbh->prepare('DELETE FROM van_reservations WHERE id = :id'); $sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->execute(); I used to validate by using this: Code: [Select] $id = isset($_GET['id']) && is_numeric($_GET['id'])?(int) $_GET['id']:0; Hi, I've seen code like this multiple times, but I don't really know what it means. function funcName(&$something) { // whatever } What exactly does the "&" do before the variable? What is the difference between these two lines Code: [Select] !isset($_POST[$requiredField]) and Code: [Select] !$_POST[$requiredField] I have this link code : echo "<a href=pop.php?git=urun&popu&id=".$row_Rec1['id'].">".$bul."</a>"; and I wanna add beetwen this code rel="facebox" help please. Hi guys, I was wondering if we have table of seats in a cinema (which makes the quantity to 1) and two users are booking the same seat at the same time on our application. How can we prevent that? I though if we create a session or even update that seat row and then if user doesn't finish the booking/or leave the browser on fora while in 10-15 minutes, that session still remains on. I'm sure we can expire that session how can we prevent both users have the same session and if one doesn't complete the purchase for any reason then how session can automatically update the database after that 15 minutes? Thanks in advance. I have data that is in a form right now being displayed in a textbox because I want the user to see the 'name' but the data that needs to be passed when submit is pressed is the id of the entity. So if I have <label id = "username" Value = "3"> Heintzman</label> can I use $_Post to retrieve that value once the form has been submitted because I dont want the data to be displayed in a textbox it looks ugly and isnt long enough for the text without editing. Say, Code: [Select] $ok = 'ABCDEFG' What is the command to check whether $ok contains 'C'? |