Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › This is driving me insane!
New Posts  All Forums:Forum Nav:

This is driving me insane!

post #1 of 14
Thread Starter 
This is driving me insane! Basically it's a reservation form. I want the client to be able to reserve only 2 hours away (before or after) an existing reservation. But for some reason it's not working! It keeps giving me not available even thogh the times are very far apart...

rtime is reserved time, trtime is the time of the reserved.

Code:
<?php
$rtime = 3.5;
$trtime = 10;

echo '</br>trtime: '.$trtime.'</br>rtime:  '.$rtime.'</br>';

if( ((rtime+2)<trtime) 
&& ((trtime-2)>rtime) )
$available = true;
else
$available = false;


if($available)
{
echo '<p>Table has been found and reserved</p>';
}
else
echo'<p>No reservation found</p>';


?>
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
post #2 of 14
At a guess, are you mixing up integer and float values? Dunno a whole lot about PHP tho so take this for what it's worth which isn't a helluva lot.
4690K System
(12 items)
 
HTPC
(9 items)
 
HP dv6 laptop
(13 items)
 
CPUMotherboardGraphicsRAM
Core i5 4690K ASRock Z97 Extreme4 XFX Radeon 7950 32 GB DDR3-2133 
Hard DriveOptical DriveCoolingOS
Samsung 850 EVO SSD Samsung DVD/CD-writer Corsair Hydro H60 Windows 7 
MonitorMonitorPowerCase
ASUS PA248Q Dell U2412M XFX 850W Black Edition XXX Fractal Design Arc Midi 2 
CPUMotherboardGraphicsRAM
Pentium Dual Core E6700 MSI G41M-P33 Combo ATI HD4350 Kingston ValueRAM DDR3-1333 
RAMHard DriveOSMonitor
Kingston ValueRAM DDR3-1333 WD Caviar Blue Windows 7 64-bit Sony 32" TV set 
Case
Apex TX-381 
CPUGraphicsRAMHard Drive
Core i5 430M GT230M (1 Gb dedicated) 8 GB DDR3-1066 640 GB 
OSMonitor
Windows 7 Home Premium (64-bit) 15.6" 
  hide details  
Reply
4690K System
(12 items)
 
HTPC
(9 items)
 
HP dv6 laptop
(13 items)
 
CPUMotherboardGraphicsRAM
Core i5 4690K ASRock Z97 Extreme4 XFX Radeon 7950 32 GB DDR3-2133 
Hard DriveOptical DriveCoolingOS
Samsung 850 EVO SSD Samsung DVD/CD-writer Corsair Hydro H60 Windows 7 
MonitorMonitorPowerCase
ASUS PA248Q Dell U2412M XFX 850W Black Edition XXX Fractal Design Arc Midi 2 
CPUMotherboardGraphicsRAM
Pentium Dual Core E6700 MSI G41M-P33 Combo ATI HD4350 Kingston ValueRAM DDR3-1333 
RAMHard DriveOSMonitor
Kingston ValueRAM DDR3-1333 WD Caviar Blue Windows 7 64-bit Sony 32" TV set 
Case
Apex TX-381 
CPUGraphicsRAMHard Drive
Core i5 430M GT230M (1 Gb dedicated) 8 GB DDR3-1066 640 GB 
OSMonitor
Windows 7 Home Premium (64-bit) 15.6" 
  hide details  
Reply
post #3 of 14
Be aware it's 5am and I'm not seeing stright but this section looks off

Code:

if( ((rtime+2)<trtime) 
        && ((trtime-2)>rtime) )
    $available = true;
else
    $available = false; 
First off why would you want them to reserve after the time alloted, but w/e

Instead of just doing less than or greater than. Try using greater than or equal to.

Math and 5am don't mix. Sorry about that

Quote:
Originally Posted by Quantum Reality View Post
At a guess, are you mixing up integer and float values? Dunno a whole lot about PHP tho so take this for what it's worth which isn't a helluva lot.
Nah he didn't specifically instantiate an integer value. In php if you don't tell it to be an int then it's w/e you stick in there
Edited by SS_Patrick - 8/6/11 at 3:36am
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
post #4 of 14
Thread Starter 
Quote:
Originally Posted by SS_Patrick View Post
Be aware it's 5am and I'm not seeing stright but this section looks off

Code:

if( ((rtime+2)<trtime) 
        && ((trtime-2)>rtime) )
    $available = true;
else
    $available = false; 
First off why would you want them to reserve after the time alloted, but w/e

Instead of just doing less than or greater than. Try using greater than or equal to.

Math and 5am don't mix. Sorry about that


Nah he didn't specifically instantiate an integer value. In php if you don't tell it to be an int then it's w/e you stick in there
No lets say there is a reservation at 5 pm. Another customer can only reserve before 3pm or after 7pm.

I tried your advice and still no luck. It's really weird because I'm tracing it by hand and it's working, but like this it's not :S

Edit: Just in case I am mistaken
3.5+2=5.5 <10
and 10-2=8>3.5
....
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
post #5 of 14
Yea it's just not agreeing with my brain. I can't tell you why. If it's still unanswered when I get up later I'll take another look

Sorry about that
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
post #6 of 14
Quote:
if( ((rtime+2)<trtime)
&& ((trtime-2)>rtime) )
Ok, so if this is a logical AND, then let's see

$rtime = 3.5;
$trtime = 10;

rtime + 2 = 5.5
This is less than trtime (10) so OK

trtime - 2 = 8
This is greater than rtime (3.5) so OK

lol i dunno

I've coded stuff in C that my brain thought was fine and the program scumbagged at me instead with weird results and it turned out to be the program logic wasn't right or the language feature I was using wasn't fully understood at first.
4690K System
(12 items)
 
HTPC
(9 items)
 
HP dv6 laptop
(13 items)
 
CPUMotherboardGraphicsRAM
Core i5 4690K ASRock Z97 Extreme4 XFX Radeon 7950 32 GB DDR3-2133 
Hard DriveOptical DriveCoolingOS
Samsung 850 EVO SSD Samsung DVD/CD-writer Corsair Hydro H60 Windows 7 
MonitorMonitorPowerCase
ASUS PA248Q Dell U2412M XFX 850W Black Edition XXX Fractal Design Arc Midi 2 
CPUMotherboardGraphicsRAM
Pentium Dual Core E6700 MSI G41M-P33 Combo ATI HD4350 Kingston ValueRAM DDR3-1333 
RAMHard DriveOSMonitor
Kingston ValueRAM DDR3-1333 WD Caviar Blue Windows 7 64-bit Sony 32" TV set 
Case
Apex TX-381 
CPUGraphicsRAMHard Drive
Core i5 430M GT230M (1 Gb dedicated) 8 GB DDR3-1066 640 GB 
OSMonitor
Windows 7 Home Premium (64-bit) 15.6" 
  hide details  
Reply
4690K System
(12 items)
 
HTPC
(9 items)
 
HP dv6 laptop
(13 items)
 
CPUMotherboardGraphicsRAM
Core i5 4690K ASRock Z97 Extreme4 XFX Radeon 7950 32 GB DDR3-2133 
Hard DriveOptical DriveCoolingOS
Samsung 850 EVO SSD Samsung DVD/CD-writer Corsair Hydro H60 Windows 7 
MonitorMonitorPowerCase
ASUS PA248Q Dell U2412M XFX 850W Black Edition XXX Fractal Design Arc Midi 2 
CPUMotherboardGraphicsRAM
Pentium Dual Core E6700 MSI G41M-P33 Combo ATI HD4350 Kingston ValueRAM DDR3-1333 
RAMHard DriveOSMonitor
Kingston ValueRAM DDR3-1333 WD Caviar Blue Windows 7 64-bit Sony 32" TV set 
Case
Apex TX-381 
CPUGraphicsRAMHard Drive
Core i5 430M GT230M (1 Gb dedicated) 8 GB DDR3-1066 640 GB 
OSMonitor
Windows 7 Home Premium (64-bit) 15.6" 
  hide details  
Reply
post #7 of 14
Thread Starter 
Ughhhh... this sucks.. I have to hand the website next week and I'm stuck on this tiny thing...
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
post #8 of 14
Try testing the individual if-then conditions separately and see what happens. Maybe the comparison is failing for some stupidly bizarre reason.
4690K System
(12 items)
 
HTPC
(9 items)
 
HP dv6 laptop
(13 items)
 
CPUMotherboardGraphicsRAM
Core i5 4690K ASRock Z97 Extreme4 XFX Radeon 7950 32 GB DDR3-2133 
Hard DriveOptical DriveCoolingOS
Samsung 850 EVO SSD Samsung DVD/CD-writer Corsair Hydro H60 Windows 7 
MonitorMonitorPowerCase
ASUS PA248Q Dell U2412M XFX 850W Black Edition XXX Fractal Design Arc Midi 2 
CPUMotherboardGraphicsRAM
Pentium Dual Core E6700 MSI G41M-P33 Combo ATI HD4350 Kingston ValueRAM DDR3-1333 
RAMHard DriveOSMonitor
Kingston ValueRAM DDR3-1333 WD Caviar Blue Windows 7 64-bit Sony 32" TV set 
Case
Apex TX-381 
CPUGraphicsRAMHard Drive
Core i5 430M GT230M (1 Gb dedicated) 8 GB DDR3-1066 640 GB 
OSMonitor
Windows 7 Home Premium (64-bit) 15.6" 
  hide details  
Reply
4690K System
(12 items)
 
HTPC
(9 items)
 
HP dv6 laptop
(13 items)
 
CPUMotherboardGraphicsRAM
Core i5 4690K ASRock Z97 Extreme4 XFX Radeon 7950 32 GB DDR3-2133 
Hard DriveOptical DriveCoolingOS
Samsung 850 EVO SSD Samsung DVD/CD-writer Corsair Hydro H60 Windows 7 
MonitorMonitorPowerCase
ASUS PA248Q Dell U2412M XFX 850W Black Edition XXX Fractal Design Arc Midi 2 
CPUMotherboardGraphicsRAM
Pentium Dual Core E6700 MSI G41M-P33 Combo ATI HD4350 Kingston ValueRAM DDR3-1333 
RAMHard DriveOSMonitor
Kingston ValueRAM DDR3-1333 WD Caviar Blue Windows 7 64-bit Sony 32" TV set 
Case
Apex TX-381 
CPUGraphicsRAMHard Drive
Core i5 430M GT230M (1 Gb dedicated) 8 GB DDR3-1066 640 GB 
OSMonitor
Windows 7 Home Premium (64-bit) 15.6" 
  hide details  
Reply
post #9 of 14
Thread Starter 
Quote:
Originally Posted by Quantum Reality View Post
Try testing the individual if-then conditions separately and see what happens. Maybe the comparison is failing for some stupidly bizarre reason.
I've been on this since morning. I've tried every possible combination I can think of...
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
Lala
(13 items)
 
  
CPUMotherboardGraphicsRAM
i7-750 @ 3.00GHz Intel DP55WB Sapphire HD 5870 @ 950/1200 1.212V Kingston 2x2GB DDR3 1333.3 
Hard DriveOSMonitorPower
1TB WD Black, 1TB WD Green Win 7 Ultimate 64 bit Samsung P2370H Thermaltake ToughPower 750W 
Case
Thermaltake M9 Black 
  hide details  
Reply
post #10 of 14
WOW

WOOOOOOWWWWW

WOWOW

I should be shot

Code:

if( ((rtime+2)<trtime) 
        && ((trtime-2)>rtime) ) 
you forgot the "$". That's what tells php to look for a variable

Don't worry you weren't the only one that missed it
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
i7 2600k Gigabyte P67-UD4-B3 GTX 580 GTX 580 
RAMHard DriveOSMonitor
Who cares? Intel SSD  Windows 7 Dell u3011 
MonitorPowerCaseMouse
Dell u3011 Seasonic x1200 800D G700 
AudioAudio
Xonar STX Beyerdynamic DT 990 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › This is driving me insane!