This topic is locked

My own listbox

3/6/2008 6:56:13 AM
PHPRunner General questions
F
Fanta author

I try in few posts before to work with the dropdown listbox created by PHPRunner, but seems to me that somewhere in the code, my javascript, from some reason does not work at all.
So I try to make my own listbox in PHPRunner but it does not work also from some reason.
My code is:

function BeforeShowAdd(&$smarty,&$templatefile)

{
global $conn;

$str = "SELECT SomeValue FROM Mytable ORDER BY SomeValue ASC;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$smarty->assign("Value",$data["SomeValue"]);
} // function BeforeShowAdd


In template, in the column where I wont to be listbox I put:

<TD class=editshade_lb style="PADDING-LEFT: 10px" width=351><select name="possible[]" id="available" SIZE="30" MULTIPLE WIDTH=512 STYLE="width: 400px" ONDBLCLICK="java script:copyToList1();">

{html_options name=$Value value=$Value output=$Value}</select></TD>


When I run the page I got that there is error in this line of code:
$smarty->assign("Value",$data["SomeValue"]);
What is wrong with my code?

J
Jane 3/6/2008

Hi,
make sure your query returns records:

global $conn;

$str = "SELECT SomeValue FROM Mytable ORDER BY SomeValue ASC;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
print_r($data);

F
Fanta author 3/7/2008

Thank you Jane, I found the mistake and I finally get the data with help of print_r from my table on my screen.
But when I put it back to:
$smarty->assign("Value",$data["SomeValue"]);
I get this kind of message:
Type of error: 256

Description of error: Smarty error: [in MyTemplate.htm line 48]: syntax error: unrecognized tag 'html_options' (Smarty_Compiler.class5.php, line 580)

URL: localhost/aaaaa/MyTemplate.php?

Error in data: C:\wamp\www\aaaaa\libs\Smarty.class5.php

Error in row: 1095
Seems to me that now he got the problem with template and with Smarty:

<TD class=editshade_lb style="PADDING-LEFT: 10px" width=351><select name="possible[]" id="available" SIZE="30" MULTIPLE WIDTH=512 STYLE="width: 400px" ONDBLCLICK="java script:copyToList1();">

{html_options name=$Value values=$Value output=$Value}</select></TD>


Now I really does not now what is the problem. Is not html_options part of Smarty???

F
Fanta author 3/7/2008

I even try to created another code in function BeforeShowAdd(&$smarty,&$templatefile), a little bit difference than this one before, but I still got the same message: syntax error: unrecognized tag 'html_options'
When I look at Smarty.class5.php and Smarty_Compiler.class5.php i did not found any function that would process html_options.

F
Fanta author 3/7/2008

I was gone to Smarty web pages and I download Smarty and I found in his orginal folder plugins function.html_options.php. I look at the the same folder in PHPRunner and it was empty.
I put it there, and my error was still there after i refresh my page. Then I put in the Smarty.class.php

<?php

if(substr(PHP_VERSION,0,1)=='4')

include("libs/Smarty.class4.php");

else

include("libs/Smarty.class5.php");

include("plugins/function.html_options.php");

?>


and my syntax error: unrecognized tag 'html_options' was still there.
Where should I put the function.html_options.php and what should I exactly do that my code work?

F
Fanta author 3/13/2008

After going around the circle I discover where is the problem.
The function.html_options.php must go inside libs/plugins file and after that I had to add one more thing, shared.escape_special_chars.php which I also put in the same place.
Than after I pass everything throw Visual Editor in PHP I got the result, but not completely, because I got only the first record from my table in the listbox and not the all values from field in my table..
What should I add or change in my code below that I finally can have all the values from table in my listbox??? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=26971&image=1&table=forumreplies' class='bbc_emoticon' alt=':P' />

function BeforeShowAdd(&$smarty,&$templatefile)

{
global $conn;

$str = "SELECT SomeValue FROM Mytable ORDER BY SomeValue ASC;

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);
$smarty->assign("Value",$data["SomeValue"]);
} // function BeforeShowAdd

J
Jane 3/14/2008

Hi,
the best way to add your own custom dropdown with values from another table is custom event (Insert PHP code snippet option on the Visual Editor tab).

Here is a sample:

global $conn;

$value = "<select onchange=\"window.location.href=this.options[this.selectedIndex].value;\">";

$str = "SELECT SomeValue FROM Mytable ORDER BY SomeValue ASC;

$rs = db_query($str,$conn);

while ($data = db_fetch_array($rs))

$value.="<option value=\"".$data["SomeValue"]."\">".$data["SomeValue"]."</option>";
$value.="</select>";

echo $value;

F
Fanta author 3/14/2008

Thank's Jane, but I also finally found solution. The code should be something like this:

function BeforeShowAdd(&$smarty,&$templatefile)

{
global $conn;

$str = "SELECT SomeValue FROM Mytable ORDER BY SomeValue ASC;

$rs = db_query($str,$conn);
while($row = db_fetch_array($rs)) {
$Value[] = $row['SomeValue'];

}
$smarty->assign("Value",$Value);
} // function BeforeShowAdd