Jump to content

killerb

Members
  • Posts

    48
  • Joined

  • Last visited

    Never

Everything posted by killerb

  1. <?php $query = "SELECT * FROM tablename WHERE colname LIKE '{$letter}%'";
  2. When you have data scattered all around different tables, the only way to optimize a heavy join is to index periodically and select your *whatever_id* from the index table. This is common practice for example on searches where the best efficiency is required on select whereas a few seconds delay on update/insert is tolerable.
  3. No can't help without getting into debugging (process of identifying cause of problem), therefore chargeable work. Sorry, not taking on small jobs presently.
  4. Parse errors mean the code is invalid PHP format, something is missing and it invalidates the PHP code so it cannot be interpreted: Needs a semicolon after , dtaken ASC" Needs a right square bracket after $week_stats[$row['wtaken']
  5. Dunno if this is the easiest or most elegant but it will achieve your requirements. You may need to tweak for performance on large data sets. This is untested, written quick for demonstration of how I have solved this sort of problem before: <?php $query = "select * from .. where dtaken >= :start_date and dtaken <= :end_date order by wtaken ASC, dtaken ASC" $bind = array('start_date'=>$start_date, 'end_date'=>$end_date); $rows = $DB->fetchAll($query, $bind); $week_stats = array(); foreach($rows as $row){ if(!array_key_exists($row['wtaken'], $week_stats)){ $week_stats[$row['wtaken'] = array( 'total' => 0, 'num' => 0 ); } // store the total of all averages for calculating averages $week_stats[$row['wtaken']]['total'] += $row['ans1']; // count number of answers for calculating averages $week_stats[$row['wtaken']]['num']++; } // calculate the averages foreach($week_stats as $stat){ $week_stats['average'] = $stat['total']/$stat['num']; } var_dump($week_stats);
  6. Another PHP'er is asking this too: http://www.phpfreaks.com/forums/index.php/topic,280683.msg1329657.html#msg1329657 You'll want to add the following method to one of your classes for converting mysql date formats to unix timestamp, or you can use the mysql function UNIX_TIMESTAMP() in your query: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_unix-timestamp <?php public static function make_tstamp($date, $default_return_value=0, $default_time='00:00:00'){ if(!is_string($date)) return $default_return_value; $date_parts = explode(' ', $date); if(count($date_parts)==1){ // date only list($year, $month, $day) = explode('-', $date_parts[0]); list($hour, $min, $sec) = explode(':', $default_time); if(intval($hour+$min+$sec+$year+$month+$day)===0){ return 0; } return mktime(intval($hour), intval($min), intval($sec), intval($month), intval($day), intval($year)); }elseif(count($date_parts)==2){ // date and time list($year, $month, $day) = explode('-', $date_parts[0]); list($hour, $min, $sec) = explode(':', $date_parts[1]); if(intval($hour+$min+$sec+$year+$month+$day)===0){ return 0; } return mktime(intval($hour), intval($min), intval($sec), intval($month), intval($day), intval($year)); }else{ // invalid date format - return default tstamp now return $default_return_value; } } Once you have the datetimes as unix timestamps and the two functions from link above, you can write something like this: <?php $row = mysql_fetch_row($resource); $start_tstamp = your_object::make_tstamp($row['start_date']); $end_tstamp = your_object::make_tstamp($row['end_date']); $duration = timestamp_difference_units_to_string(timestamp_difference_to_units($start_tstamp, $end_tstamp));
  7. I used this function to display time remaining until an online auction finishes, which is typically days, hours, mins and secs. It does not handle leap years or months, but it may be sufficient for what you need: <?php $from_tstamp = mktime(0, 0, 0, 2, 1, 2009); $to_tstamp = mktime(0, 0, 2, 2, 1, 2009); var_dump(timestamp_difference_units_to_string(timestamp_difference_to_units($from_tstamp, $to_tstamp))); function timestamp_difference_to_units($from_tstamp, $to_tstamp){ $from_tstamp = intval($from_tstamp); $to_tstamp = intval($to_tstamp); $seconds_remaining = $to_tstamp-$from_tstamp; if($seconds_remaining < 0){ $retval = timestamp_difference_to_units($to_tstamp, $from_tstamp); foreach($retval as $k=>$v){ $retval[$k] = -$v; } return $retval; } $num_years = 0; $num_days = 0; $num_hours = 0; $num_mins = 0; $num_secs = 0; while($seconds_remaining >= 31536000){ $num_years++; $seconds_remaining -= 31536000; } while($seconds_remaining >= 86400){ $num_days++; $seconds_remaining -= 86400; } while($seconds_remaining >= 3600){ $num_hours++; $seconds_remaining -= 3600; } while($seconds_remaining >= 60){ $num_mins++; $seconds_remaining -= 60; } $num_secs = $seconds_remaining; $seconds_remaining = 0; return array( 'years' => $num_years, 'days' => $num_days, 'hours' => $num_hours, 'minutes' => $num_mins, 'seconds' => $num_secs ); } function timestamp_difference_units_to_string($diff){ $parts = array(); if($diff['years']>0){ $parts[] = $diff['years'].' years'; } if($diff['days']>0){ $parts[] = $diff['days'].' days'; } if($diff['hours']>0){ $parts[] = $diff['hours'].' hours'; } if($diff['minutes']>0){ $parts[] = $diff['minutes'].' mins'; } if($diff['seconds']>0){ $parts[] = $diff['seconds'].' secs'; } $last_part = array_pop($parts); $retval = implode(', ', $parts); if(count($parts)>0){ $retval .= ' and '.$last_part; }else{ $retval .= $last_part; } return $retval; }
  8. Interested to see this architecture, particularly "to get the data put wherever it needs to be put", is the code available?
  9. Reminds me of a problem I had with exec and mysqldump, the -p parameter was fine in shell as such: mysqldump -u root -p mypass but when running through PHP's exec() function it had to have no space after the -p argument: mysqldump -u root -pmypass Took a bit of stabbing in dark to discover this, hope the info might be of some help.
  10. It is common practice to put PHP processing at top of the file and have the form posting to the same file, this way PHP attempts to process a submitted form if possible and displays the form afterwards, whether or not the form was processed. Your task to list files and upload files is better to do with two files: upload.php list.php Begin with upload.php, place your html form into that file and above your form, put your processing logic within PHP tags. eg: <?php if(count($_POST)>0){ // processing goes here, validate and store the uploaded files } ?> <html> <body> <?php // output any errors that were encountered during form processing ?> <form method="post"> <!-- ommitting action attribute forces form submission to same uri --> </form> </body> </html> On your list page you will want to get all files into an array and then loop them: <?php $dh = opendir(dirname(__FILE__)); $files = array(); while($file = readdir($dh)){ if($file=='..' || $file=='.') continue; $files[] = $file; } ?> <html> <body> <h1>List of files:</h1> <ul> <?php foreach($files as $file){ echo '<li>'.$file.'</li>'; } ?> </ul> </body> </html> This way the PHP logic is separated from the HTML markup, and the PHP logic within HTML is for display only. It is generally advised that all PHP data retrieval and preparation is done before HTML begins, as you can see in 2nd example that all files are prepared into an array before the template begins. Its a personal preference of course, but you will find such conventions assist the separation of roles according to MVC principles, even without applying strict MVC rules. Also using the same file (or identical file path and file name in /controllers and /templates) for processing and template assists in tracking down the right file when it comes to maintaining a code base in future.
  11. If both servers run PHP, you will need one server to open a connection, request/push the xml from/to the other server. If pushing, you should use HTTP post to send the xml data, otherwise you can use curl, fread or file_get_contents for pulling an xml download into PHP and then store it as required. Note if you are able to see the xml on your server already, half the work is done you just need a PHP script on the recipient server to download the xml and store it, and of course a cron or something to invoke the script when required.
  12. killerb

    PDFLib

    There's FPDF which I've used with no problems and there's Zend_Pdf, which I only played with a year ago or so.
  13. Hi, yes it is an option to install the system on localhost and set the client dns to my IP so peer can perform tests, however was wanting to know if it is possible to set PHP's time() value at runtime because that would be much easier and preferable, guess from answers here its not the easiest solution..
  14. Hi, thanks for help, yes it is a development server but I am a programmer and not sysadmin, wanting to know if I can do it with PHP without having to open a ticket.
  15. Try wrapping the test in count($_POST) to be sure the form has been submitted, your condition is evaluating false because a) isset($_POST['go']) is false until form is submitted b) !empty($_POST['name']) is false until form submitted c) preg_match($pattern, $_POST['name']) is false because form not submitted EG: <?php class error { var $error = "You must put in a name"; var $good = "good work, name has been entered"; function myError(){ $pattern = '/[A-Za-z]+/'; if(count($_POST)>0){ // form submitted if(isset($_POST['go']) && !empty($_POST['name']) && preg_match($pattern, $_POST['name'])) { return $this->good; } else { return $this->error; } }else{ // form not submitted return ''; } } }
  16. Working with PHP 5.2.6 where date() and time() are used all the way through instead of DateTime object, wanting to test some scripts where certain actions happen on the nth day of the month. We obviously can't wait until the nth day of month to run the tests, would be quite good to be able to set timestamp at runtime similar to setlocale but giving an explicit timestamp, trying DateTime::setTimestamp gives the "undefined method" error since it is a 5.3 feature. Is there a way to do this without changing the server clock, sysadmin is resistant to requests lmao.
  17. Ah ok, patience please while I verify: My software uses open source Crypt, Input Filter and DOM classes, intending to release the full source except the admin controllers encrypted (which are purely my own code). Free for unlimited download and use to small fee subscribers. The branding is encrypted into the admin actions. Users can pay to get an unencrypted copy and remove branding similar to the CMS Made Simple license. Just need to know this business plan is not illegal Cheers!
  18. I don't want to encrypt the open source files, just the admin controllers so the copyright notices and branding can't be removed. Rather confused about open source licenses, does it mean that if I use open source files in my application that all my application must be open source?
  19. Well, yeah, jpeg is working fine, of course it doesn't give me transparency. Adding imagecolortransparent works for .png, but not for gif. As well, the png is aliased to black matt. It is pretty clear that this is a realm of PHP I need to study, so I will do that sometime soon. For the meantime, I must get on with it. This project is getting bigger and bigger by the day.
  20. . . . and why can't i find anything about it already!!? I have this process: [code]<?php move_uploaded_file($_FILES[$name]['tmp_name'],$dest); $image_p = imagecreatetruecolor($tile_oblique_width, $h); $image = imagecreatefromgif($dest); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tile_oblique_width, $h, $dims['0'], $dims['1']); $image = imagegif($image_p,$dest); ?> [/code] Problem is that I get a nasty black background where it should be transparent. If I just move_uploaded_file without resizing, it is transparent as I want. Is there actually a way to do this? - There must be! Cheers.
  21. Why the big bg image? It looks like a perfect candidate for CSS styling. Might I suggest that you make a repeat-x loop of the top bar only (the diagonal lines), and slice it carefully so it is recurring. Like this: [code] body{background:#e3e3e3 url('../images/main_bg.gif') repeat-x top left;} [/code] then <div id="main">. This should be the container for everything, by the look of this design: [code] #main{border:solid 1px white; background:#FFFFFF;color:#333333;padding:0;margin:60px 180px;} [/code] You now nest the other divs inside it. Notice I dont use padding until the actual text elements? because margins are easier to use, and more specific. [code] #header,#footer{background:#333344;height:60px;} [/code] Now, to lay out the page: [code] <div id="main"> <div id="header">   <div class="left third">home link here</div>   <div class="two_thirds">web and graphic design portfolio</div> </div> <div id="rightCol"><p>Right Col</p></div> <div id="mainContent"><p>Main Content</p></div> <div id="footer">Footer</div> </div> [/code] And to style the page: [code] .third{width:33.33%} .two_thirds{width:66.66%} .left{float:left} .clear{clear:both;} #header .left{border-right:solid 1px white;margin:8px;} #header .two_thirds{margin:8px;} #right-col{width:80px;position:absolute;margin:0;right:0;} #mainContent{margin-right:80px;} p{padding:8px;} [/code] See my .left, .third, .clear classes? There is an example of how you can define styles and use them in your HTML. You might have classes like .w80, .w120, .w180, .w220 for example, then when doing a form, you can use them to style as you go: [code] <form> <fieldset><legend>Welcome! - Please Log In</legend> <input type=text name=email class=w220><br / <input type=text name=pass class=w120><br / <input type=submit value="Go >>" class=w60><br / </fieldset> </form> [/code] There is a tidy system, and being a system, you can apply the same SS to any new site as you develop, then tweak it later. Mainly, I want to say dont use padding until the very last element, it limits control of positioning. Reduce your image use, there is no point mucking round with images, the bandwidth, load delay, and the restrictions it places. Especially in a case like this when the styling can be done perfectly well with simple CSS. I notice your drop-shadow on the main. You will want to use [url=http://freewebs.com/good-code]Custom borders with CSS[/url]
  22. Build it to work in FF. IE6 is soon to die when IE7 is released this month. IE7 behaves like FF. use this: [code] <!--[if lte IE 6]> <link rel="stylesheet" type="text/css" href="filename-ie.css"> <![endif]--> [/code] Use that file to hold all the hacks that are for IE, like the famous 'IE rounding bug'. All other browsers will ignore that file. Some good practice is what you need. The more frustrated you get, the more you will remember the right way to do it, and yes, CSS is frustrating. Once you learn it, it is great. Most of us just dont seem to get the right direction when learning, so it multiplies the work. I am a firm believer in books for learning code. Here are some axioms. You might already know them, but in case you dont, here goes: [list] [*]Use static or relative positioning by default, absolute positioning does not stretch the parent element. [*]Don't use width:100% - margin:0 will do the same thing (stretch the margin to the padding of the parent) [*]if centering divs, text-align:center in the parent, and margin:auto in the child. IE sets margin:auto by default, but it is not the W3C way. (I like IE in a lat of ways, in a lot of ways I dont. Glad it is finally standardised.) [*]Use margins rather than padding - padding interferes with positioning the child elements, and gets quite frustrating. [*]Only padding on elements that hold text (p,blockquote,td,label,textarea,input tags) [*]Clear all floats, except where the text is to wrap-around the image/div. [/list] I dont know what else to say, from there on it just gets too specific.
  23. Ouch! - It happens, for sure. Basically, layers are just divs. I use the term layers when divs are about to occupy the same space, then they behave like layers, and you have a certain amount of control using the z-index property. z-index determines the layer-order. With z-index, it is calculated by browsers automatically in the order of the elements on the page. It is common to use divs as containers (layers). Actually, images are treated as layers when it comes to calculating the z-index. [b][u]Layers within layers[/u][/b] Eg: [code] <div id="d1"> <div id="d2"></div> <div id="d3"></div> <img id="i1" /> </div> [/code] Presume the code sits alone in the body tag. [list] [*]Div#d1 gets a z-index of 1 in the body element. [*]Div#d2 gets a z-index of 1 in the Div#d1 element. [*]Div#d3 gets a z-index of 2 in the Div#d1 element. [*]Img#i1 gets a z-index of 3 in the Div#d1 element. [/list] If you need to override this, you can assign z-index properties to specific elements, but the best way is to design your page structure with this in mind.
  24. Is the file being written to the folder? - permissions on the desination folder itself? If the file is there, Can you get it by typing the url directly into your browser?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.