Page 2 of 2

Posted: Tue Aug 24, 2004 10:44 am
by Draco_03

Code: Select all

array (
  'DATE_SUB(`loanerin`,INTERVAL `loanerout` DAY)' => NULL,
)
that's what it output

Posted: Tue Aug 24, 2004 11:00 am
by feyd
I think DATE_SUB is the wrong function to use..

maybe something like:

Code: Select all

SELECT * FROM loan_clients WHERE `loanerin` IS NULL AND `loaderout` <= DATE_SUB(NOW(), INTERVAL 1 WEEK) AND DAYOFWEEK(`loanerout`) = DAYOFWEEK(DATE_SUB(NOW(), INTERVAL 1 WEEK))

Posted: Tue Aug 24, 2004 12:11 pm
by Draco_03

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
can t fetch the line.. and can't echo it directly
print_r gave me

Code: Select all

1
..

But i don't understand

Code: Select all

WHERE loanerin IS NULL
??
In fact loanerin is not null when i make this check. I want to take the difference between the loaner in an loaner out ( number of days the client kept it)

Posted: Tue Aug 24, 2004 12:26 pm
by feyd
ok.. so switch it to IS NOT NULL.. and check mysql_error() if the returned result is false...

Posted: Tue Aug 24, 2004 12:29 pm
by Draco_03

Code: Select all

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WEEK) AND DAYOFWEEK(`loanerout`) = DAYOFWEEK(DATE_SUB(NOW(),

Posted: Tue Aug 24, 2004 12:32 pm
by Draco_03
if i change 1 WEEK to 7 DAY it gives me

Code: Select all

array (
  0 => '1',
  'clientsid' => '1',
  1 => 'Igor',
  'fname' => 'Igor',
  2 => 'Polanski',
  'lname' => 'Polanski',
  3 => 'Key to health',
  'ciename' => 'Key to health',
  4 => '416-736-1223',
  'ciephone ' => '416-736-1223',
  5 => '45 oakmaunt rd. #501',
  'address ' => '45 oakmaunt rd. #501',
  6 => 'toronto',
  'city' => 'toronto',
  7 => 'M6P 2M4',
  'postal' => 'M6P 2M4',
  8 => '',
  'hoursmade' => '',
  9 => '2004-07-27 16:30:00',
  'loanerout' => '2004-07-27 16:30:00',
  10 => '2004-08-11 10:30:00',
  'loanerin' => '2004-08-11 10:30:00',
  11 => '3',
  'loanerid' => '3',
  12 => '1',
  'loanerflag' => '1',
)

Posted: Tue Aug 24, 2004 12:34 pm
by feyd
oops.. week is mysql 5.. change it to

Code: Select all

7 DAY

Posted: Tue Aug 24, 2004 12:38 pm
by Draco_03
Okay but to make the numbers of days kept (loanerin minus loanerout) i just use

Code: Select all

$date_diff=$myarray[10] - $myarray[9];
something like that ?

Posted: Tue Aug 24, 2004 12:48 pm
by feyd
I'd do the calculation in sql:

Code: Select all

SELECT *, TO_DAYS(`loanerout`) - TO_DAYS(`loanerin`) `days out` FROM loan_clients ..........

Posted: Tue Aug 24, 2004 1:19 pm
by Draco_03
Thx a lor feyd
here's the code you helped me with

Code: Select all

<?php
if(!isset($_SESSION['name'])){
	echo("Need to log in first <a href="index.php">click here</a> to log in");
}else{
	$sql = "SELECT * FROM loan_clients WHERE clientsid='$clientsid'";
	$result = mysql_query($sql);
	$row = mysql_fetch_row($result);
	$sql_math = "SELECT *, TO_DAYS(`loanerin`) - TO_DAYS(`loanerout`) `days out` FROM loan_clients";
	$calcul = mysql_query($sql_math) or die(mysql_error());
	$date_diff = mysql_fetch_row($calcul);
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php 
	echo("
		<tr>
		<td><strong>First Name</strong></td>
		<td>$row[1]</td>
		</tr>
		<tr>
		<td><strong>Last Name</strong></td>
		<td>$row[2]</td>
		</tr>
		<tr>
		<td><strong>Compagny Name</strong></td>
		<td>$row[3]</td>
		</tr>
		<tr>
		<td><strong>Compagny Phone</strong></td>
		<td>$row[4]</td>
		</tr>
		<tr>
		<td><strong>Address</strong></td>
		<td>$row[5]</td>
		</tr>
		<tr>
		<td><strong>City</strong></td>
		<td>$row[6]</td>
		</tr>
		<tr>
		<td><strong>Postal Code</strong></td>
		<td>$row[7]</td>
		</tr>
		<tr>
		<td><strong>Hours Made</strong></td>
		<td>$row[8]</td>
		</tr>
		<tr>
		<td><strong>Loaner Sent</strong></td>
		<td>$row[9]</td>
		</tr>
		<tr>
		<td><strong>Loaner Received</strong></td>
		<td>$row[10]</td>
		</tr>");
		if($row[12] == 1){
		echo("
		<tr>
		<td><strong>Time Kept</strong></td>
		<td>$date_diff[13] days</td>
		</tr>
		");
		}
}
?>
</tr>
</table>
<br /><a href="../summary.php">Go back</a>
Thx (it gives me the numbers of days... just to know will it always give only days ? never anything else no hours no minutes right

Posted: Tue Aug 24, 2004 1:40 pm
by feyd
the query addition will only do days.. you can add in stuff for hours and minutes if you want with additional math..

Posted: Tue Aug 24, 2004 1:47 pm
by Draco_03
k thx :D
May the god of informatique bless you

amen == True