Forum Moderators: coopster
Period1-MTW-ENG-wA-Details=Test
Period2-MF-ENG-wA-Details=Test
Period3-TW-ENG-wA-Details=Test
I have a table that i have uploaded a snapshot of here: <snip>
what i want to be able to do is maybe convert the results of the $title into some sort of variables so i can slot them into the relavant cell(s) in the table. For example: The first line result of $title needs to be placed into the table for Period1, wA on Monday Tuesday and Wednesday. Oh and the actual information that needs to be placed in the cell itself is Details=Test minus the "Details="
Does anyone have any idea how i can possibly do this?
I would really much appreciate anyones help in this.
Thanks
[edited by: dreamcatcher at 8:54 am (utc) on July 14, 2009]
[edit reason] No personal urls, thanks. [/edit]
if your cells are named, or at least numbered in your iterations then you can use the numbers out of the rows to pull them.
if those strings are all the same with Period# then you could pull the number out of that string to use as the array position
if the only data is what is after the = then split on =
<?php
$myvar = 'Period1-MTW-ENG-wA-Details=Test';
$myvararr = split('=',$myvar);
$myvalue = $myvararr[1];
$myvararr = explode('-',$myvararr[0]);
$myvar2 = str_replace('Period','',$myvararr[0]);
$myendarr[$myvar2] = $myvalue;
echo '<pre>';
print_r($myendarr);
echo '</pre>';
?>
or in a loop
<?php
$strarr = array('Period1-MTW-ENG-wA-Details=Test1','Period2-MF-ENG-wA-Details=Test2','Period3-TW-ENG-wA-Details=Test3');
foreach ($strarr as $myvar) {
$myvararr = split('=',$myvar);
$myvalue = $myvararr[1];
$myvararr = explode('-',$myvararr[0]);
$myvar2 = str_replace('Period','',$myvararr[0]);
$myendarr[$myvar2] = $myvalue;
}
echo '<pre>';
print_r($myendarr);
echo '</pre>';
?>
In my table, there are basically 3 period columns and 5 rows below them to indicate Monday-Friday. The days are identified from the array by the letters MTWHF. so for example:
Period1-MTW-ENG-wA-Details=Test needs to display The value Test in the Column that is Period1-wA not period1-wB and it actually needs to be displayed in the rows Monday, Tuesday and Wednesday.
any ideas how i can do this?
if you wanted to be complicated, based on what you have already you could construct an array per day and easily slot your pieces into them
you can easily expand the grab after I stripped out the string 'Period' as well
it was an example of how, you will need to adapt and tailor it to your exact situation
cross collating arrays is always fun, especially when you make a mistake, it replicates ;)
currently in example loop code, it will result in the following being displayed: [1] => Test1
but if thats split by the days then it would read
[M] => Test1
[W] => Test1
your loop would encompass these rows
// this gets the value from the end of the string
$myvar2 = str_replace('Period','',$myvararr[0]);
// this creates your array
$myendarr[$myvar2] = $myvalue;
you would need to change the last line and add some lines before that to walk through the days of the week