php

Adding time in PHP

I am pulling a datetime from a mysql db and i would like to add X hours to it then compare it to the current time. So far i got $dateNow = strtotime(date('Y-m-d H:i:s')); $dbTime = strtotime($row[0]); then i tried $dbTime + strtotime("4 hours"); but 4 hours seem to add 4hrs to the current time instead of raw 4hours. How do i add X ho...

PHP - define constants versus using config.ini

Performance wise, I was wondering which method of defining constants/settings is better? Using a config.ini file through a class like Zend_Config_Ini or just defining a series of php constants? ...

Does PHP5 call __destruct() if you use a redirect?

I found that PHP5 isn't calling a __destruct() function if I have the following setup: class test { __destruct() { echo 'hehe'; exit; } } header('Location: http://test.com/'); exit; It never calls the destruct function ...

Convert kilobytes to bytes in PHP

Hi, how can I convert kilobytes to bytes in php? Let's say I get the value 22.2 kb and I want to return this in bytes. Thanks, Max ...

Calling a controller within a controller?

As far as best practices go is this recommended? I have a comments controller + model that needs to be called in an items and profiles controller. The comments controller automatically loads the comments model. Is it acceptable to call the comments controller directly from the items and profile controller, or is the "best practice" way ...

Mysql and PHP Problem?

It seems there is a parse error with my mysql and php code can some please help me clean up this code. $tag = mysql_real_escape_string($_POST['tag']); $query = 'UPDATE tags SET count = count+1 WHERE tag = '.$tag; mysql_query($query,$dbc); if( !mysql_affected_rows() ) { $query = 'INSERT INTO tags (tag,count) V...

Auto add to database on last day of month

I have a database which stores the work my staff do. One particular query I run tells me how much money I owe them for the current month (month to date), based on the hours that I have recorded for them. However, I would like to store this information into a table itself, for various reasons, not least to record whether I have actually...

Lightbox not working in Ajax.Updater div (prototype)

I am using an Ajax.Updater call to produce a single rental listing's information in a div. A dropdown menu of all the rental listings starts things off, and the div is hidden until the user selects a listing, in which case a javascript effect makes it appear and the updater is executed. A php file is called from the updater which quer...

PHP PDO prepared statements

I was told today that I should really be using PDO and prepared statements in my application. Whilst I understand the benefits, I am struggling to understand how I implement them into my workflow. Aside from the fact that it makes code much cleaner, should I have a specific database class which houses all my prepared statements or should...

Correct Date and Time Columns in MySQL

I have a timezone mismatch I need to correct in a table. All dates and times before unix timestamp 1253568477 need to have 5 hours added to their values to make them equal GMT. I have the following columns... date (data type date), off by -5 hours time (data type time), off by -5 hours timestamp (data type int), this column is the co...

$var instead of $_GET['var'] in PHP?

Ok I cannot remember the details on this but on some servers you can use $var instead of $_GET['var'] to access a variable in the URL, I know this is BAD but I can't remember why it is bad? ...

PHP form won't update my MySQL database.

Can someone please help me fix this code I f***ed up it wont update my database anymore. DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', ''); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'tags'); if ($dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)) { if (!mysql_select_db (DB_NAME)) { ...

Calculation error - need help!

Hello, I need to ask someone for a big favor. What you see in the code below are my calculations for train movement for a train game I am writing. There is a problem with the calculations, but I just can't seem to find it. The problem seems to be located in this code: if($trainRow['direction'] == '-') { $trackUnitCount = ...

Specifying a callback function in preg_replace_callback?

I have some code like this (this is a simplified example): function callback_func($matches) { return $matches[0] . "some other stuff"; } function other_func($text) { $out = "<li>"; preg_replace_callback("/_[a-zA-Z]*/","callback_func",$desc); $out .= $desc ."</li> \r\n"; return $out; } echo other_func("This is a _test"); ...

Yii Framework Resources

Yii is a nice php framework. (In my un-experienced view). I was wondering if anybody knows any good resources for it? This is a community wiki. Self described as a high-performance component-based PHP framework best for developing large-scale Web applications. It has a rich set of features, is purely objected orientated and has a growi...

PHP SimpleXML doesn't preserve line breaks in XML attributes

I have to parse externally provided XML that has attributes with line breaks in them. Using SimpleXML, the line breaks seem to be lost. According to another stackoverflow question, line breaks should be valid (even though far less than ideal!) for XML. Why are they lost? [edit] And how can I preserve them? [/edit] Here is a demo fil...

How to pass file into PHP CLI?

I have a PHP script named "scipt" and a textfile called 'data.txt'. Right now I can execute script, but then I need to type in "data.txt". Is there any way to pass in data.txt as a parameter to "script" so I can run this thing in one line automated? Right now I'm typing: php script {enter} // script runs and waits for me to type filena...

PHP if statement issue when checking for variable value

I'm trying to just write a simple PHP if statement that checks if a custom field has anything entered into or if it has been left blank. when it is blank it is meant to not print anything to the page, if something is set in the custom field then it should create a li element with an a tag inside of it. here is my code so far: <ul clas...

Building site.. custom inventory system.. cart recomendation?

I am building a site using code igniter. I am developing a custom product catalog using php and mysql. What is the best way to go about making those products purchaseable online. I thought about writing my own cart, but I am a little worried about how much time that would take. Most carts I come across online are full fledge invent...

Dynamic Child Class generation - PHP

I have an abstract "object" class that provides basic CRUD functionality along with validation, etc. Typically I would use the __autoload($name) magic function to load a class that would exist in its own file, named the same as the class I wish to lazy load. The code would look something like this, which as you can imagine becomes quit...