Page 1 of 1
URGENT- HELP NEEDED ASAP!
Posted: Mon Aug 04, 2003 3:53 pm
by sh_inxs
Hi,
I have a php file that extracts data from the db and assigns it to a variable as in the following lines of code:
$part_list_auto = part_selectlist_auto("",'') ;
$t->set_var('parts_list_auto',$part_list_auto);
A template file uses this variable to display the data in a text area as:
<textarea cols="100" rows="30" name="myname">{parts_list_auto}</textarea>
Now, i chnaged the code so as to put the huge data in an array as $part_split_auto which is declared as an array in the php file.
and use the following statement too in the php file :
$t->set_var('parts_split_auto',$part_split_auto);
I have been totally unsuccessful in all ways to get the text area to display this array.
Pls. help me out!!!
Post Variables problem
Posted: Tue Aug 05, 2003 8:45 am
by kendall
Yo man,
That's not alot to go on there...you need to be a little more detailed. how is the varibable being outputed through and included file? what about if you are reading it from a text file?
i see you have a '<textarea cols="100" rows="30" name="myname">{parts_list_auto}</textarea> ' now i dont no what going on here but if your trying to place markers with the information you may need to be dong a read() data and str_replace() (i dont know what youre doing) i assume your'e not trying to echo $parts_list_auto else you would have had exactly tthat. but if the data is in arrays you proably need to check your looping...again i am not clear as to what is going on here...so you need to be more detailed.
Kendall
DETAILS PROVIDED - PLS. HELP!
Posted: Tue Aug 05, 2003 11:21 am
by sh_inxs
This problem is part of the phpgroupware stuff available for download.
Code segment from class.gr.inc.php
$part_split_auto = array();
$part_split_auto = part_splitlist_auto("",'');
$part_list_auto = part_selectlist_auto("",'')
$t->set_var('parts_list_auto',str_replace("'$part'","'$part' selected",$part_list_auto));
$t->set_var(str_replace("'$part'","'$part' selected",$part_split_auto));
The above called functions are defined in functions.inc.php to extract data from a db & return it in string and array format respectively.
Code segment from gradd.php
$gr = CreateObject('ck-inv.gr') ;
$t = CreateObject('phpgwapi.Template',$phpgw->common->get_tpl_dir('ck-inv'));
$t->set_file('report','grscreen.tpl') ;
$t->set_block('report','detail','detail_section');
$t->set_var('lang_title',lang('Add Goods Receipt (GR)'));
$gr->gr_detail_write($t, $g, $posted, $delete, $newrow);
$t->parse('out','report',True);
So gradd.php calls the function gr_detail_write() from class.gr.inc.php which obtains the values for $part_split_auto and $part_list_auto.
The information obtained is displayed & accessed in the concerned template file grscreen.tpl using
Code segment from grscreen.tpl:
<textarea cols="100" rows="30" name="myname">{part_list_auto}</textarea>
<textarea cols="100" rows="30" name="myname">{part_split_auto[1]}</textarea>
Now. this works fine for {part_list_auto} and the entire huge list is displayed in the text box. However, i am not sure of the notation i should use to display say, one element of the array {part_split_auto} at a time. I have not yet looped it in the template file since i am still testing if it displays at aleast one element of the array.
Also, the file class.gr.inc.php displays the entire array list successfully using
foreach($part_split_auto as $key=>$value) {
echo $key." - ".$value."<br>";
}
This verifies that all is fine until being accessed properly from the template file.
Essentially, i am looking for the notation to access an php array variable from a template file under the following conditions
- The template file has access to variables from the php file since {parts_list_auto} is displayed successfully.
- I am unable to use any form of php code in the template file using <?php ?> tags.
- A file class.Template.inc.php under phpsysinfo/includes had the following defnition for set_var() function
/* public: set_var(array $values)
* values: array of variable name, value pairs.
*
* public: set_var(string $varname, string $value)
* varname: name of a variable that is to be defined
* value: value of that variable
*/
function set_var($varname, $value = "") {
if (!is_array($varname)) {
if (!empty($varname))
if ($this->debug) print "scalar: set *$varname* to *$value*<br>\n";
$this->varkeys[$varname] = "/".$this->varname($varname)."/";
$this->varvals[$varname] = $value;
} else {
reset($varname);
while(list($k, $v) = each($varname)) {
if (!empty($k))
if ($this->debug) print "array: set *$k* to *$v*<br>\n";
$this->varkeys[$k] = "/".$this->varname($k)."/";
$this->varvals[$k] = $v;
}
}
}
I understand that looking at the entire code could be very confusing, hence i have provided the concerned code snippets. Pls. let me know if any more info is required.
Shankar
Posted: Tue Aug 05, 2003 11:40 am
by kendall
Shank,
Yo man I got to admit im no PRO at this thing so excuse me for that...but man i am not sure how this information output process is but it seems to me that the template is read() if so then there prbably needs to have a {part_split_auto[2]} and so forth... because you can't really output an $part_split_auto array() just so...you got to access it using a loop such as while(x<count(part_aplit_auto)){ echo part_split_auto[x]x++;} or foreach(part_split_auto as $ky= $val){echo $ky $val}
Posted: Tue Aug 05, 2003 11:55 am
by sh_inxs
Hey kendall,
- I am not able to read even the data in {part_split_auto[1]} in the template file. I intend to loop after i am able to read the data in at least one element of the array.
- "while(x<count(part_split_auto)){ echo part_split_auto[x]x++;} or foreach(part_split_auto as $ky= $val){echo $ky $val}"
Where do i put this code?? I cannot put this in the template file since it does not recognize php tags. And the above code works just fine in the php file class.gr.inc.php The issue is to get it to be displayed in a text area on a web page.
Hence the requirement to access it from a template file.
- Shankar
Posted: Tue Aug 05, 2003 12:19 pm
by qartis
Code: Select all
$part_split_auto = array();
$part_split_auto = part_splitlist_auto("",'');
$part_list_auto = part_selectlist_auto("",'')
$t->set_var('parts_list_auto',str_replace("'$part'","'$part' selected",$part_list_auto));
$t->set_var(str_replace("'$part'","'$part' selected",$part_split_auto));
<textarea cols="100" rows="30" name="myname">{part_list_auto}</textarea>
<textarea cols="100" rows="30" name="myname">{part_split_auto[1]}</textarea>
Now. this works fine for {part_list_auto} and the entire huge list is displayed in the text box. However, i am not sure of the notation i should use to display say, one element of the array {part_split_auto} at a time. I have not yet looped it in the template file since i am still testing if it displays at aleast one element of the array.
So you want to display only one element from the array, not the whole shebang? In that case, try adding
Code: Select all
$part_list_auto = $part_list_auto[1];
after
Code: Select all
$part_split_auto = array();
$part_split_auto = part_splitlist_auto("",'');
$part_list_auto = part_selectlist_auto("",'')
$t->set_var('parts_list_auto',str_replace("'$part'","'$part' selected",$part_list_auto));
$t->set_var(str_replace("'$part'","'$part' selected",$part_split_auto));
Just remember, that will forget all the other elements to $part_list_auto, so it might break your code somewhere.
Ok so...
Posted: Tue Aug 05, 2003 12:28 pm
by sh_inxs
Yup that works...However i mainly wanted to get the whole array to be displayed in the template file. The test was to see if the notation can get it gto diplsy the data one element of the array at a time.
Now as i am able to only transmit the elements of the array string by string to the template file and not as an array and if i have 10000 elements in my array, what could i do to get it to work???
Posted: Tue Aug 05, 2003 12:41 pm
by Stoker
sh_inxs, do _not_ send private messages to people with links to your threads.. Thats like knocking on all the doors in your home town asking everybody to come look at your home made car and try figure out why it wont start..
Posted: Tue Aug 05, 2003 12:51 pm
by sh_inxs
My sincere apologies to all users whom i sent private messages. However i would be very grateful if anyone could help me out of this problem.
regards,
Shankar
Posted: Tue Aug 05, 2003 2:41 pm
by kendall
Ohhhhhhhhhhhhhhhhhhhhh.....is that what he's trying to get at??? My Bad...inexperience question answerer....
[quote]Yup that works...However i mainly wanted to get the whole array to be displayed in the template file. The test was to see if the notation can get it gto diplsy the data one element of the array at a time.
Now as i am able to only transmit the elements of the array string by string to the template file and not as an array and if i have 10000 elements in my array, what could i do to get it to work???[/quote]
MAn I don't think you can whitout performing some loop function...unless you knew how many array elements there are you can prbably do a part_split_auto[1], [2] , [3].....but that is futile. I only see it working if you do a loop day loop and stack the elements into a variable
maybe something like....
[syntax=php]foreach($part_split_auto as $autoPart){
$part_split_auto .= $autoPart.','; // use some thing to dilimit it whether comma or html <li> tag
}[/syntax]
thus the template will show the variable $part_split_auto which has the elements in dilimited format....get it?
fellas...am i on the rigth page here?...geez i dont even know if im rite
Kendall
[quote]
sh_inxs, do _not_ send private messages to people with links to your threads.. Thats like knocking on all the doors in your home town asking everybody to come look at your home made car and try figure out why it wont start..[/quote]....LMAO@Stoker