php

Why does `intval(19.9 * 100)` equal `1989`?

Boy, this one is really weird. I expect the following code to print 1990, but it prints 1989! $val = '$19.9'; $val = preg_replace('/[^\d.]/','',$val); $val = intval($val * 100); echo $val; Why on earth is this happening? Edit: and this code: $val = '$19.9'; $val = preg_replace('/[^\d.]/','',$val); echo $val . "<br>"; $val = $val *...

Connect two database from 2 different host

Hi, currently I have two websites: 1. A website connected to mySQL database in host A. 2. A website connected to Ms. Access database in Host B. Is there anyway if I update the database in Host B, the database in Host A can be updated automatically? Thank you. Really appreciate your help. ...

Change the target of a symlink with PHP

How can I change the target of a symlink with PHP? Thanks. ...

Cookie won't unset

OK, I'm stumped, and have been staring at this for hours. I'm setting a cookie at /access/login.php with the following code: setcookie('username', $username, time() + 604800, '/'); When I try to logout, which is located at /access/logout.php (and rewritten to /access/logout), the cookie won't seem to unset. I've tried the following: ...

What is the best way to implement a big (1GB or more) file uploader website in PHP or Java?

What is the best way to implement a big (1GB or more) file uploader website in PHP or Java? Using the default way of uploading in PHP or Java results in running out of RAM space and slowing the website very dramatically. ...

How to fill a drop down menu

I want to populate a drop down menu with a column from a MySQL database. I have the rest of my database set up, but at the moment it is just a text entry box and it would be easier just to select the actually entry from a list. Also does anyone know of a good tutorial or site that has tutorials and example codes for PHP and MySQL ...

why this Javascript function doesn't work?

I use the following javascript function, function get_check_value(formId,checkboxId,TxtboxId) { alert(formId); var c_value = ""; for (var i=0; i < document.formId.checkboxId.length; i++) { if (document.formId.checkboxId[i].checked) { c_value = c_value + document.formId.checkboxId[i].value + "\n"; } } alert...

Display X divs randomly out of a possible Y.

How do I randomly display 3 divs out of a possible 10 in total? This is what I have tried so far: HTML: <div id="1">Content 1</div> <div id="2">Content 2</div> <div id="3">Content 3</div> <div id="4">Content 4</div> <div id="5">Content 5</div> <div id="6">Content 6</div> Javascript: function randomiseDiv() { // Define how man...

wget return downloaded filename

I'm using wget in a php script and need to get the name of the file downloaded. For example, if I try <?php system('/usr/bin/wget -q --directory-prefix="./downloads/" http://www.google.com/'); ?> I will get a file called index.html in the downloads directory. EDIT: The page will not always be google though, the target may be an im...

free geolocation geoip, are they viable?

I'm trying to get a visitor's location based on their IP, pretty common stuff. My research so far shows that there's a database from MaxMind that costs $370 + $90/month... not the type of cost I can afford. Then there's a free version called GeoLite City. Anyone used these before? Drop a quick line here please. Why is one free and the ...

How to check how many times something occurs in a string in PHP

I want to check how many instances of the letter "a" appears in a certain string. What is the function for this? I need it to return an integer value. ...

exec() command from web server in php

Is there anyway to use atrm command to remove queue job from PHP web application? I wrote a shell script to remove the queue job but it doesn't work well. #! /bin/sh export PATH=/usr/local/bin:$PATH echo atrm 3700 2>&1 ...

CakePHP: Custom Function in bootstrap that uses $ajax->link not working

Hello I have two questions: (1) Is it best practice to create global custom functions in the bootstrap file? Is there a better place to store them? (2) I am unable use the following line of code in my custom function located in my bootstrap.php file: $url = $ajax->link ( 'Delete', array ('controller' => 'events', 'action' => 'd...

Letting users create customized Bundles in Magento.

We are building an e-commerce site where users can create their own bundles with products of their choice. Other users can then buy these bundles. Please guide me as to how a bundle can be created based on the products selected by user and store this bundle. From whatever little I have read, I can create a module which will do this. Is ...

A question about the order of pagination

Currently I'm deal with a history message page using Cakephp.And I got a problem about records' order.In the controller,codes about pagination as follows $this->paginate['Msg'] = array('order'=>'Msg.created desc'); $msgs = $this->paginate('Msg'); $this->set('historymsgs',$msgs); Then I got the first page which contains the latest mess...

PHP - database not selected. What is wrong with my code?

Hi, I am learning PHP and tried to connect to MySQL. Altough I am using select DB, is still reports "No database selected". What is wrong, please? Thanks. <?php $user="test"; $pass="aaa"; ConnectToDb(); function ConnectToDb() { $pripojeni=mysql_connect('localhost',$user,$pass); $selectedDB=mysql_select_db('1a'); if($query=mysql_qu...

PDOStatement::bindParam() not setting AI value from MySQL insert?

I have a simple insert statement using PDO php class. the 'id' column is identity (doy) with autoincrement. $statement = $db->prepare('INSERT INTO demographics (id,location_id,male,ethnicity_id,birthyear) VALUES (:id,:location_id,:male,:ethnicity_id,:birthyear)'); $statement->bindParam(':id',$demo->id,PDO::PARAM_INT,4); $statement->b...

How do I maintain a constant reference to an email on Gmail while access a copy of it from my Google App application?

Hi guys, I'm working on shifting my local web application to google apps. I have an account already for google apps for business and right now I need to work on the functionality of interacting with email. Let me give a synopsis - my web app currently was set up that a cron job would download all emails from a set mailbox into a databas...

Can I trigger PHP garbage collection to happen automatically if I have circular references?

I seem to recall a way to setup the __destruct for a class in such a way that it would ensure that circular references would be cleaned up as soon as the outside object falls out of scope. However, the simple test I built seems to indicate that this is not behaving as I had expected/hoped. Is there a way to setup my classes in such a wa...

Robust Directory Manager in PHP

This is a general question. What are some techniques you employ to prevent the links in your PHP code from breaking every time you move a file or move a file into a different directory? ...