This topic is locked

Addin a listbox with sql query to the list page

4/9/2008 6:32:42 AM
PHPRunner General questions
S
stevenf author

Hi I need to add a listbox where I can populate a table...
For example, I have a table called websites and I need to listbox populated with it.
So the table has for example:
website1

website2
etc..
On select, I need to pay to list all records where website (selected) = website on the table.
Can this be done pls?
Thanks

J
Jane 4/9/2008

Hi,
you can do it using custom event (Insert PHP code snippet option on the Visual Editor tab).

Here is a sample:

$str = "

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

<option value=\"\">Please select</option>

<option value=\"website1_list.php\">website1</option>

<option value=\"website1_list.php\">website2</option>

</select>";

echo $str;

S
stevenf author 4/9/2008

Hi,

you can do it using custom event (Insert PHP code snippet option on the Visual Editor tab).

Here is a sample:


OK, I know how to create the listbox but how do I populate it from the database and then do a custom list query please?

J
Jane 4/9/2008

Hi,
to select values from database use this code:

global $conn;

$strSQL = "select field1,field2 from tablename";

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

$data = db_fetch_array($rs);
echo $data["field1"];

echo $data["field2"];


Then add parameter to the url:

<option value=\"website1_list.php?field1=".$data["field1"]."\">website1</option>



and check it in the Before SQL query event:

$strWhereClause = whereAdd($strWhereClause,"field1=".$_REQUEST["field1"]);

S
stevenf author 4/9/2008

Hi,

to select values from database use this code:
Then add parameter to the url:
and check it in the Before SQL query event:


I'll give it a shot. thanks jane <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=27795&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

S
stevenf author 4/10/2008



I'll give it a shot. thanks jane <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=27843&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />


Hi Jane, I have a problem, please see below:
Ref: to select values from database use this code:

QUOTE

global $conn;

$strSQL = "select field1,field2 from tablename";

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

$data = db_fetch_array($rs);
echo $data["field1"];

echo $data["field2"];
Where do I put the obove code?
Then add parameter to the url:

QUOTE

<option value=\"website1_list.php?field1=".$data["field1"]."\">website1</option>
Again Where/how do I add a parameter?
and check it in the Before SQL query event:

QUOTE

$strWhereClause = whereAdd($strWhereClause,"field1=".$_REQUEST["field1"]);
I understand this one <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=27843&image=2&table=forumreplies' class='bbc_emoticon' alt=':)' />

S
stevenf author 4/11/2008

Hi I need to add a listbox where I can populate a table...

For example, I have a table called websites and I need to listbox populated with it.
So the table has for example:
website1

website2
etc..
On select, I need to pay to list all records where website (selected) = website on the table.
Can this be done pls?
Thanks


Can anyone help please?

S
stevenf author 4/11/2008

I really need help on this one please <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=27867&image=1&table=forumreplies' class='bbc_emoticon' alt=':unsure:' />

J
Jane 4/11/2008

Hi,
add these samples to your code where you create dropdown:

global $conn;

$strSQL = "select field1,field2 from tablename";

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

$data = db_fetch_array($rs);
$str = "

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

<option value=\"\">Please select</option>

<option value=\"website1_list.php?field1=".$data["field1"]."\">field1</option>

<option value=\"website2_list.php?field1=".$data["field2"]."\">field2</option>

</select>";

echo $str;

S
stevenf author 4/11/2008

Hi,

add these samples to your code where you create dropdown:


But do I do it via PHPRunner or do I edit some page...How please? Like this?
Please see screenshot:


The above is what I've tried but I cannot see any drop-down box anywhere.
THanks again
Steven.
THanks
Steven.

J
Jane 4/11/2008

You can use this code in your custom event.

S
stevenf author 4/11/2008

Hi Jane,
If you look here I've posted a screenshot.
http://www.asprunner.com/forums/index.php?...art=#entry27876
I get no errors but cannot see any drop-down listbox anywhere...what I'm I doing wrong please?
Thanks
Steven

S
stevenf author 4/11/2008

Here is the code:
function image_admin_Event2(&$params)

{
// Put your code here.

global $conn;

$strSQL = "select website from websites";

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

$data = db_fetch_array($rs);
$str = "

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

<option value=\"\">Please select</option>

<option value=\"websites_list.php?website=".$data["website"]."\">website</option>

</select>";

echo $str;

} // function image_admin_Event2
Is this right?

J
Jane 4/11/2008

Steven,
it's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

S
stevenf author 4/11/2008

Steven,

it's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.


But, I'm I putting the code in the right place according to my screenshot?