This topic is locked

Dropdown box in list page

1/27/2009 6:39:57 PM
PHPRunner General questions
N
nickditrolio author

Could someone explain how to make a dropdown box using a lookup table in a view page?(I can do it on an Add or an Edit page)..

My lookup table is called week_list. It has a bunch of dates. When the user goes to a ShowPicks List page, I want the dropdown box to be on the top of the table. The user picks a week from the dropdown list to display all the picks for that date. It also needs a default value.

Thank you.
Also, from looking at all the questions and answers, people use code snippets all the time. Is there a tutorial on this like how to retrieve data, etc. I hate to keep asking these simple questions, But I'm new to this and PHP language and I can't find a tutorial on how to write the code.(that's kind of why I bought PHP RUnner in the first place!) Is it in a PHP book? What is Smarty? Thanks for the help.

A
alang 1/27/2009

Have you considered using the advanced search? - may be possible to do something without too much PHP coding.

J
Jane 1/28/2009
N
nickditrolio author 1/28/2009

Could someone explain how to make a dropdown box using a lookup table in a view page?(I can do it on an Add or an Edit page)..

My lookup table is called week_list. It has a bunch of dates. When the user goes to a ShowPicks List page, I want the dropdown box to be on the top of the table. The user picks a week from the dropdown list to display all the picks for that date. It also needs a default value.

Thank you.
Also, from looking at all the questions and answers, people use code snippets all the time. Is there a tutorial on this like how to retrieve data, etc. I hate to keep asking these simple questions, But I'm new to this and PHP language and I can't find a tutorial on how to write the code.(that's kind of why I bought PHP RUnner in the first place!) Is it in a PHP book? What is Smarty? Thanks for the help.

N
nickditrolio author 1/28/2009

Thank you, Jane..you are priceless..however, I entered the code and got this error:
I put the code in a PHP snippet right where I want the dropdown box. here's the code:
[color=#8B0000]// Put your code here.

echo "Your message";

//create dropdown box

$str = "";

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

<option value=\"\">Please select</option>";
//select values from database

//create dropdown box

$str = "";

$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex].value;\"><option value=\"\">Please select</option>";
//select values from database

global $conn;

$strSQL = "select week from week_list";

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

while ($data = db_fetch_array($rs))

$str.="<option value=\"week_list_list.php?a=search&value=1&SearchFor=".$data["week"]."&SearchOption=Contains&SearchField=week\">".$data["week"]."</option>";
$str.="</select>";

echo $str;

J
Jane 1/29/2009

Nick,
this error means that you page was broken on the Visual Editor tab.

Try to reset page, then create new custom event and add your code again.

N
nickditrolio author 1/29/2009

Thank you, Jane..you are priceless..however, I entered the code and got this error:

I put the code in a PHP snippet right where I want the dropdown box. here's the code:
[color=#8B0000]// Put your code here.

echo "Your message";

//create dropdown box

$str = "";

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

<option value=\"\">Please select</option>";
//select values from database

//create dropdown box

$str = "";

$str.= "<select onchange=\"window.location.href=this.options[this.selectedIndex].value;\"><option value=\"\">Please select</option>";
//select values from database

global $conn;

$strSQL = "select week from week_list";

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

while ($data = db_fetch_array($rs))

$str.="<option value=\"week_list_list.php?a=search&value=1&SearchFor=".$data["week"]."&SearchOption=Contains&SearchField=week\">".$data["week"]."</option>";
$str.="</select>";

echo $str;


that worked. I now have a drop down box with the list from the table. Thank you..but..it sends me to the advanced search page! I want it to return to the same list page with the option I select in the where clause of the sql statement!

I know what the SQL statement should be. How do I implement it? For instance:

I want the default to be:

The dropdown box is in the 'week' column. [color=#808000]The user selects a different date(ex. 2009-09-13)

All I want is for it to return to the list page using the sql statement:

Select * from picks where week= '2009-09-13'

N
nickditrolio author 1/30/2009



that worked. I now have a drop down box with the list from the table. Thank you..but..it sends me to the advanced search page! I want it to return to the same list page with the option I select in the where clause of the sql statement!

I know what the SQL statement should be. How do I implement it? For instance:

I want the default to be:

The dropdown box is in the 'week' column. [color=#808000]The user selects a different date(ex. 2009-09-13)

All I want is for it to return to the list page using the sql statement:

Select * from picks where week= '2009-09-13'

N
nickditrolio author 1/30/2009

Thanks for the help, Jane..It now works great. I'm getting the hang of it. Just one more minor question if you don't mind..I need to enter a where clause for a particular week(2009-09-06) if it's the first time entering the page. Otherwise, it gives records for all the dates until I pick one from the dropdown box.

Thanks again.

Nick