Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A query in PHP results other ting the im MySQL 1

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
0
0
IL
Hi everyone,
This is my sql query:
Code:
SELECT HOUR(TIMEDIFF('16:55','16:45')) + MINUTE(TIMEDIFF('16:55','16:45'))/60;
When I run it on my MySQL display this is what I get:
to_forum1_gbhwrn.gif

I'd like that query to be operated usin PHP code. This is my code:
Code:
<?php //MyINITIAL.PHP
$MyHOST = 'localhost';
$MyUSER = 'yossi';
$MyPASS = 'yoss4qpines';
$MyDB = 'test';
?>

Code:
<?php //MyLOGIN.PHP
$MyCONNECTION = NEW MYSQLI($MyHOST,$MyUSER,$MyPASS,$MyDB);
IF(!$MyCONNECTION)
DIE('Gevald' .MYSQLI_CONNECT_ERROR());
MYSQLI_SET_CHARSET($MyCONNECTION,'UTF8');
?>

Code:
<?php // to_forum.php
REQUIRE_ONCE 'MyINITIAL.php';
REQUIRE_ONCE 'MyLOGIN.php';

$MyCONNECTION = NEW MYSQLI($MyHOST,$MyUSER,$MyPASS,$MyDB);
IF(!$MyCONNECTION)
DIE(MYSQLI_CONNECT_ERROR());
MYSQLI_SET_CHARSET($MyCONNECTION,'UTF8');

$aaa=time('16:50');
$bbb=time('16:55');
$ccc="select hour(timediff('$bbb','$aaa')) + MINUTE(TIMEDIFF('$bbb','$aaa'))/60;";
$result = $MyCONNECTION->query($ccc);
if(!$result) echo $MyCONNECTION->error;
else
$res = $result->fetch_array(MYSQLI_NUM);
print_r($res);
?>
When I run my php code this is what I get:
to_forum2_dxpqxx.gif

Why do I not get the desired result from my PHP as in my MySQL display?
Thanks
 
The time() function in PHP does not take any parameters. It merely returns the current time in seconds.

Passing a string to it will return the same value for both times: The current time.

Getting the difference between that, will return 0 which translates to nothing in your results..

You can simply pass the time stings as they are, and it should work.









----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top