Forum Moderators: coopster

Message Too Old, No Replies

pass array to same page

         

nshack31

3:49 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



im using the followig code where $e is an array

<a href=\"admincourse.php?addall=addall&month=$month&year=$year&courseid=$courseid&d=$e\">

but its not being passed as an array its being passed as some text "array", what is the correct way to sort this?!

thanks

Anyango

4:10 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By just echo of Array Name, all array values cannot be printed. You will have to loop whole aray and make those values part of your url as before.

nshack31

4:14 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



is there another way of doing this? what happens is i have a function called getMonth, within this function i have the following...

$e[] = $d;//store days in e for later

It correctly stores the days of the current month within $e[]

I then have a link on my page (outside of getMonth function)....

it gets add all from a link on the page that is the following...

<a href=\"admincourse.php?addall=addall&month=$month&year=$year&courseid=$courseid&d=$e\"><font color=\"#000000\"><u>Click Here</u></font></a>

and use the following code (outside the function) to try and find the array..

else if (isset($_GET['addall']))
{
$month=$_GET['month'];
$year=$_GET['year'];
$courseid=$_GET['courseid'];
$e[]=$_GET['d'];
print_r($e);
}

but i cant get the array data, can anybody help?

nshack31

4:45 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



i gues what im asking is how do you pass array variables from one function/class to another?

Anyango

6:13 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i guess thats not what you are asking anyways.


Discussion: pass array to same page

phparion

7:28 pm on Feb 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well, first of all you have to understand what an Array is in fact and how can you manipulate Array. just to tell you, what you are doing wrong is that you want to send whole array with one link, its not possible, if you want to send all the array variables then use loop to create multiple links for each and every value of array then you can use it in the right way, just by writing array name in one link you cant pass the whole array.

sorry if i am not reading between the lines but i think this is what you wanted to know.

nshack31

7:51 pm on Feb 24, 2006 (gmt 0)

10+ Year Member



thats great thanks! i used a different method in the end, the following will read the days from my database and it will return all days from the selected month that the days in the database fall on....

$monthcal=$_GET['month'];
$yearcal=$_GET['year'];
$courseid=$_GET['courseid'];

function getDays($month, $weekdays = '', $year = '') {
$weekdays = empty($weekdays)? array('Monday') : $weekdays;
$year = empty($year)? date('Y') : $year;
$days = date('t', mktime(0,0,0,$month,1,$year));
$out = array();
for ($i = 1; $i <= $days; $i++) {
$day = mktime(0,0,0,$month,$i,$year);
if (in_array(date('l', $day), $weekdays))
$out[] = $i;
}

return $out;
}
$query = "SELECT day,time FROM coursetimes where time!= ''";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$day[]=$row['day'];
$time[]=$row['time'];
}

$daylist = getDays($monthcal, $day, $yearcal);

// to output, simply implode()
echo "times: " . implode(', ', $daylist) . "<br />\n";


i then insert this into the database but theres a problem...

//insert into database
foreach ($daylist as $day) {
$queryins="INSERT INTO coursedates (courseid, day, month, year, time) VALUES ('$courseid', '$day', '$monthcal', '$yearcal', '$time')";
mysql_query($queryins) or die(mysql_error());
}

the problem is TIME, for example Monday could be 5 - 7 and friday could be 4.30 til 5.30. Hpw do I edit the function to include time also?! so that time is inserted into the database also

thanks!

phparion

6:34 pm on Feb 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



well, the syntax of the function mktime is like,

int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

you used three '0's in your function, you can set time by using

time (hours, minute, second, , , ) in place of these three 0s.