Can someone tell me where i've gone wrong

I have the following code

[php]

<?php require_once('Connections/connect.php'); mysql_select_db($database_connect, $connect); $strDateFrom = date('Y-m-d', mktime(0 ,0 , 0, $monthFrom, $dayFrom, $yearFrom)); $strDateTo = date('Y-m-d', mktime(0 , 0, 0, $monthTo, $dayTo, $yearTo)); function createDateRangeArray($strDateFrom,$strDateTo) { // takes two dates formatted as YYYY-MM-DD and creates an // inclusive array of the dates between the from and to dates. // could test validity of dates here but I'm already doing // that in the main script $aryRange=array(); $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4)); $iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4)); if ($iDateTo>=$iDateFrom) { array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry while ($iDateFrom<$iDateTo) { $iDateFrom+=86400; // add 24 hours array_push($aryRange,date('Y-m-d',$iDateFrom)); } } return $aryRange; } $aryDates=createDateRangeArray($strDateFrom,$strDateTo); $dates_dates_dates = print_r($aryDates); /* $sql="INSERT INTO bookings (prop_ref, bookings) VALUES ('1','$dates_dates_dates')"; $result = mysql_query($updateSQL, $connect) or die(mysql_error()); */ ?> <?php echo $strDateFrom,'
'; // JUST TO SEE WHATS HAPPENING echo $strDateTo,'



'; // JUST TO SEE WHATS HAPPENING echo $dates_dates_dates,'
'; // JUST TO SEE WHATS HAPPENING ?>

[/php]

andy all its returning is

Array ( [0] => 2010-01-01 [1] => 2010-01-02 [2] => 2010-01-03 [3] => 2010-01-04 [4] => 2010-01-05 [5] => 2010-01-06 [6] => 2010-01-07 [7] => 2010-01-08 [8] => 2010-01-09 [9] => 2010-01-10 [10] => 2010-01-11 [11] => 2010-01-12 [12] => 2010-01-13 [13] => 2010-01-14 [14] => 2010-01-15 [15] => 2010-01-16 [16] => 2010-01-17 [17] => 2010-01-18 [18] => 2010-01-19 [19] => 2010-01-20 [20] => 2010-01-21 [21] => 2010-01-22 [22] => 2010-01-23 [23] => 2010-01-24 [24] => 2010-01-25 [25] => 2010-01-26 [26] => 2010-01-27 [27] => 2010-01-28 [28] => 2010-01-29 [29] => 2010-01-30 [30] => 2010-01-31 [31] => 2010-02-01 [32] => 2010-02-02 [33] => 2010-02-03 [34] => 2010-02-04 [35] => 2010-02-05 [36] => 2010-02-06 [37] => 2010-02-07 [38] => 2010-02-08 [39] => 2010-02-09 [40] => 2010-02-10 [41] => 2010-02-11 [42] => 2010-02-12 [43] => 2010-02-13 [44] => 2010-02-14 [45] => 2010-02-15 [46] => 2010-02-16 [47] => 2010-02-17 [48] => 2010-02-18 [49] => 2010-02-19 [50] => 2010-02-20 [51] => 2010-02-21 [52] => 2010-02-22 [53] => 2010-02-23 [54] => 2010-02-24 [55] => 2010-02-25 [56] => 2010-02-26 [57] => 2010-02-27 [58] => 2010-02-28 [59] => 2010-03-01 [60] => 2010-03-02 [61] => 2010-03-03 [62] => 2010-03-04 [63] => 2010-03-05 [64] => 2010-03-06 [65] => 2010-03-07 [66] => 2010-03-08 [67] => 2010-03-09 [68] => 2010-03-10 [69] => 2010-03-11 [70] => 2010-03-12 [71] => 2010-03-13 [72] => 2010-03-14 [73] => 2010-03-15 [74] => 2010-03-16 [75] => 2010-03-17 [76] => 2010-03-18 [77] => 2010-03-19 [78] => 2010-03-20 [79] => 2010-03-21 [80] => 2010-03-22 [81] => 2010-03-23 [82] => 2010-03-24 [83] => 2010-03-25 [84] => 2010-03-26 [85] => 2010-03-27 [86] => 2010-03-28 [87] => 2010-03-29 [88] => 2010-03-30 [89] => 2010-03-31 [90] => 2010-04-01 [91] => 2010-04-02 [92] => 2010-04-03 [93] => 2010-04-04 [94] => 2010-04-05 [95] => 2010-04-06 [96] => 2010-04-07 [97] => 2010-04-08 [98] => 2010-04-09 [99] => 2010-04-10 [100] => 2010-04-11 [101] => 2010-04-12 [102] => 2010-04-13 [103] => 2010-04-14 [104] => 2010-04-15 [105] => 2010-04-16 [106] => 2010-04-17 [107] => 2010-04-18 [108] => 2010-04-19 [109] => 2010-04-20 [110] => 2010-04-21 [111] => 2010-04-22 [112] => 2010-04-23 [113] => 2010-04-24 [114] => 2010-04-25 [115] => 2010-04-26 [116] => 2010-04-27 [117] => 2010-04-28 [118] => 2010-04-29 [119] => 2010-04-30 [120] => 2010-05-01 [121] => 2010-05-02 [122] => 2010-05-03 [123] => 2010-05-04 [124] => 2010-05-05 [125] => 2010-05-06 [126] => 2010-05-07 [127] => 2010-05-08 [128] => 2010-05-09 [129] => 2010-05-10 [130] => 2010-05-11 [131] => 2010-05-12 [132] => 2010-05-13 [133] => 2010-05-14 [134] => 2010-05-15 [135] => 2010-05-16 [136] => 2010-05-17 [137] => 2010-05-18 [138] => 2010-05-19 [139] => 2010-05-20 [140] => 2010-05-21 [141] => 2010-05-22 [142] => 2010-05-23 [143] => 2010-05-24 [144] => 2010-05-25 [145] => 2010-05-26 [146] => 2010-05-27 [147] => 2010-05-28 [148] => 2010-05-29 [149] => 2010-05-30 [150] => 2010-05-31 [151] => 2010-06-01 [152] => 2010-06-02 [153] => 2010-06-03 [154] => 2010-06-04 [155] => 2010-06-05 [156] => 2010-06-06 [157] => 2010-06-07 [158] => 2010-06-08 [159] => 2010-06-09 [160] => 2010-06-10 [161] => 2010-06-11 [162] => 2010-06-12 [163] => 2010-06-13 [164] => 2010-06-14 [165] => 2010-06-15 [166] => 2010-06-16 [167] => 2010-06-17 [168] => 2010-06-18 [169] => 2010-06-19 [170] => 2010-06-20 [171] => 2010-06-21 [172] => 2010-06-22 [173] => 2010-06-23 [174] => 2010-06-24 [175] => 2010-06-25 [176] => 2010-06-26 [177] => 2010-06-27 [178] => 2010-06-28 [179] => 2010-06-29 [180] => 2010-06-30 [181] => 2010-07-01 [182] => 2010-07-02 [183] => 2010-07-03 [184] => 2010-07-04 [185] => 2010-07-05 [186] => 2010-07-06 [187] => 2010-07-07 [188] => 2010-07-08 [189] => 2010-07-09 [190] => 2010-07-10 [191] => 2010-07-11 [192] => 2010-07-12 [193] => 2010-07-13 [194] => 2010-07-14 [195] => 2010-07-15 [196] => 2010-07-16 [197] => 2010-07-17 [198] => 2010-07-18 [199] => 2010-07-19 [200] => 2010-07-20 [201] => 2010-07-21 [202] => 2010-07-22 [203] => 2010-07-23 [204] => 2010-07-24 [205] => 2010-07-25 ) 2010-01-01
2010-07-25

I’m tring to put it into and sql but its giving an error [size=99px]Query was empty[/size]

Does anyone have any ideas

[php]
$sql=“INSERT INTO bookings (prop_ref, bookings) VALUES (‘1’,’$dates_dates_dates’)”;
$result = mysql_query($updateSQL, $connect) or die(mysql_error());
[/php]
$updateSQL hasn’t been defined. (error_reporting(E_ALL) would have showen it)

[php]
$aryDates=createDateRangeArray($strDateFrom,$strDateTo);
$dates_dates_dates = print_r($aryDates);
[/php]
are u trying to assign the output of print_r($aryDates) to $dates_dates_dates?

in that case u have to use print_r($aryDates,TRUE). http://php.net/print_r
but i would use something like $dates_dates_dates = implode(’,’,$aryDates) as the arraykeys don’t matter and later u may convert it back to an array: $aryDates = explode(’,’,$dates_dates_dates)

Thanks for that, it looks a bit better but what I am trying to do is put each individual date into the database any suggestions.

I have tried

[php]$dates_dates_dates = “’”.implode("’,’",$aryDates)."’";[/php]

This gives you the SQL format

‘2010-01-19’,‘2010-01-20’

But return the following error

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 ‘2010-01-19’,‘2010-01-20’’)’ at line 1

use a seperate db for the dates (if ur not doing that already)

then i always use an id (even if not needed yet)
and then u may just have a foreighn key and the date.

TABLE booking_dates
PRIMARY_KEY id (autoincrement)
prop_ref
date (only one)

then u need a foreach loop to insert them, and a while($row=mysql_fetch_) loop to get them back.

foreach loop to insert them, and a while($row=mysql_fetch_) loop to get them back

Now i’m totally lost

Done it at last, 2days its taken.

:lol: :lol:

[php]

$aryDates=createDateRangeArray($strDateFrom,$strDateTo);
foreach($aryDates AS $requests) {
$updateSQL=sprintf(“INSERT INTO bookings (prop_ref, bookings) VALUES (‘1’,’$requests’)”);
$result = mysql_query($updateSQL, $connect) or die(mysql_error());
}
[/php]

I also did this if anyone wants to use it

[php]

Month <?php for ($i = 01; $i <= 12; $i++) echo ''.date('F',mktime(0,0,0,$i)).''; ?> Day <?php for ($i = 01; $i <= 31; $i++) echo ''.$i.''; ?>

[/php]

u can’t insetrt a variable number of fields into a database.

what u are trying is:

| prop_ref | bookings   |
| 1        | 2010-01-01 | 2010-01-02 | 2010-01-03 |
| 2        | 2010-01-23 | 2010-01-24 | 2010-01-25 | 2010-01-26 | 2010-01-27 |
...

the right way to do it is:

| prop_ref | dates      |
| 1        | 2010-01-01 | 
| 1        | 2010-01-02 | 
| 1        | 2010-01-03 |
| 2        | 2010-01-23 | 
| 2        | 2010-01-24 | 
| 2        | 2010-01-25 | 
| 2        | 2010-01-26 | 
| 2        | 2010-01-27 |
...

or better:

| id | prop_ref | dates      |
|  1 | 1        | 2010-01-01 | 
|  2 | 1        | 2010-01-02 | 
|  3 | 1        | 2010-01-03 |
|  4 | 2        | 2010-01-23 | 
|  5 | 2        | 2010-01-24 | 
|  6 | 2        | 2010-01-25 | 
|  7 | 2        | 2010-01-26 | 
|  8 | 2        | 2010-01-27 |
...

to get this done u may use code like:
[php]
foreach($aryDates as $onedate)
{
$sql=“INSERT INTO booking_dates (prop_ref, onedate) VALUES (‘1’,’$onedate’)”;
$result = mysql_query($sql, $connect) or die(mysql_error());
}
[/php]
(“a foreach loop to insert them”)

and when u are reading the data later u need:
[php]
$sql=“SELECT * FROM booking_dates prop_ref = ‘1’”;
$result = mysql_query($sql, $connect) or die(mysql_error());

$aryDates=array();
while($row=mysql_fetch_assoc($result))
{
$aryDates[]=$row[‘onedate’];
}
[/php]
(“a while($row=mysql_fetch_) loop to get them back”)

hope this makes it clearer.

good to know u found that out on ur own.

Its just knowing what to look for, i’m used to the terminology pf visual basic and this is all a bit new to me.

Sponsor our Newsletter | Privacy Policy | Terms of Service