Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 10-12-2007, 11:40 PM
pipesportugal's Avatar
Sergeant Major
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 99
Cool how to fill combobox with dynamic php variables ?

Hello dear colleagues from vodahost forum,

I would like to have a dynamic visualization in a combobox created at BV software, for that purpose I am placing on both "Item text" and "Value" fields of the "edit item" box, the following code:

<?php echo $option_one; ?>
<?php echo $option_two; ?>
<?php echo $option_three; ?>

I named the combobox combo_color and at the Tab index placed nothing.

Then I have created in the same webpage an html box that assigns several values to these variables. I used the following code:

<?php
$option_one = 'White';
$option_two = 'Black';
$option_three = 'Red';
?>

I also tried to insert this same code in the "page html" option in several different places, start, between..., inside..., beginning...,etc and none of my trials worked.

Can someone give me some ideas of what am I making wrong ?

Thx,
pipesportugal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 10-13-2007, 05:51 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,024
Default Re: how to fill combobox with dynamic php variables ?

Your approach is correct. However, make sure that the html box is, in the page code flow, BEFORE the combobox (and the entire form) itself, otherwise the values don't exist yet when the combobox is created. If necessary right click on the html box and select Move to Back.

Now, if it doesn't work with the code

$option_one = "White";
$option_two = "Black";
$option_three = "Red";

placed in the Start of Page,

make sure that you have set your page to publish as php


Please also note that this approach is rather static. I mean, you have to define the options statically, and the number of options is static also. Usually, the dynamic population of comboboxes is used to populate it with values that are contained in a database table. Now, since these values can be continously changes, both as values and as number, you need a dynamic approach like the followingexample. Let's say that you have a form that uploads products into a cart database. During upload, you have to define which category the product belongs to. So, you have a table called "categories" in your database, and you have there all your categories. Now, when you upload a product, your script must look into this table, retrieve the category IDs and titles, and present them in the combobox as options. Here is what you do:
<?
require ("dbconnect.php");
$query = "SELECT categoryID, category_title FROM categories ORDER BY category_title ASC";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result)) {
$category_title[] = $row['category_title'];
$categoryID[] = $row['categoryID'];
}
?>
<select name="categoryID" size="1" id="Combobox1"
><?
$option = "<option value=\"Please select a Category\">Please select a Category</option> \n";
for ($i = 0; $i < count($category_title); $i++) {
$option .= "<option ";
$option .= "value=\"$categoryID[$i]\">$category_title[$i]</option> \n";
}
echo $option;
?>
</select>

As you can see, there is a first part in blue color. This one retrieves the category titles and IDs from the database (i have included here the code that is required to connect to the database, however, i do not have here the dbconnect file code. It is simply the code necessary to connect to the database)

Then there is a second part in blue, that is responsible for populating the combobox. The parts in black are autocreated by BV.

if you are using a BV form, then the first part in blue goes into the object (combobox) Before Tag and the second in the Inside Tag
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 10-13-2007, 08:13 PM
pipesportugal's Avatar
Sergeant Major
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 99
Default Re: how to fill combobox with dynamic php variables ?

Hi Naval Design,

I tried very hard but there was no way I could, at the "inside tag", retrieve the information from inside the array loaded at the "before tag".

There was also an extra (not needed) "}" in the "inside tag" code, but I removed it.

This is the code I used:
BEFORE TAG:
<?php
include("include/dbconnect.php");
$pedido = "SELECT cod_tiposusers, des_tiposusers FROM tabela_tiposusers";
$resultado_busca = mysql_query($pedido,$db);
?>

INSIDE TAG:
<?php
$option = "<option value=\"Seleccione actividade\">Seleccione actividade</option> \n";
while ($row = mysql_fetch_array($resultado_busca))
{
$opcao = $row["des_tiposusers"];
$option .= "<option ";
$option .= "value=\"$opcao\">$opcao</option> \n";
}
echo $option;
?>

This was the only way I could make it work, many, many hours after I started.
This a "User type" table with 2 fields only, "User number" and "User description" and I am interested in displaying in the combobox the description only.

I imagine that You made copy/paste of the code You've put at this thread before, but I haven't been able to make it work. There was no way, I couldn retrieve in the "INSIDE TAG" the array that I loaded at the "BEFORE TAG".

This routine does work in Your program, right ?

Thank You so much for all the help,

pipesportugal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 10-13-2007, 08:37 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,024
Default Re: how to fill combobox with dynamic php variables ?

Yes, i took the code from one of my scripts, and is perfectly working. Make it:

<?
require ("dbconnect.php");
$query = "SELECT des_tiposusers FROM tabela_tiposusers";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result)) {
$des_tiposusers[] = $row['des_tiposusers'];
}
?>

and


><?
$option = "<option value=\"Seleccione actividade\">Seleccione actividade</option> \n";
for ($i = 0; $i < count($des_tiposusers); $i++) {
$option .= "<option ";
$option .= "value=\"$des_tiposusers[$i]\">$des_tiposusers[$i]</option> \n";
}
echo $option;
?



For before Tag and Inside Tag of the Combobox

be careful to the >< at the start and the missing > at the end of the second code.

I prefer storing the values in an array and not echoing them directly from the database as this allowes me to make particular validations / checks on the values, if necessary, before feeding them into the combobox.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 10-14-2007, 09:46 PM
pipesportugal's Avatar
Sergeant Major
 
Join Date: Jul 2007
Location: Oporto - Portugal
Posts: 99
Talking Re: how to fill combobox with dynamic php variables ?

Quote:
Originally Posted by navaldesign View Post
be careful to the >< at the start and the missing > at the end of the second code.

I prefer storing the values in an array and not echoing them directly from the database as this allowes me to make particular validations / checks on the values, if necessary, before feeding them into the combobox.
Hi Naval Design,

Those particular details of the >< and the other one of the "close php tag" without the >, have passed completed aside from my eyes.

In fact it works as it should with the great great advantage of being able to test the values of the arrays.

This was Precious help,

Thank You again and till next time....

pipesportugal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 06-04-2008, 01:14 PM
Private
 
Join Date: Jun 2008
Location: Australia
Posts: 4
Default Re: how to fill combobox with dynamic php variables ?

I am a novice at this sort of thing but i have learnt a great deal from this post. I have adapted the code you offered and it seems to work by adding as many entries into the combo box as there are in the database however, they appear blank. Any help would be much appreciated.

Example

Quote:
<?
require ("actdb.php");
$query = "SELECT name FROM combatant_table WHERE damage!=0 AND ally='T'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$name[] = $row['name'];
}

?>
<select name="name" size="1" id="Combobox1">
<?
$option = "<option value=\"Please select a Category\">Please select a Category</option> \n";
for ($i = 0; $i < count($name); $i++) {
$option .= "<option ";
$option .= "value=\"$name[$i]\">$name[$i]</option> \n"; }
echo $option;
?>
</select>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 06-04-2008, 02:00 PM
Private
 
Join Date: Jun 2008
Location: Australia
Posts: 4
Default Re: how to fill combobox with dynamic php variables ?

I have also adapted using the two variables for the sake of the exercise and get:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/.lazar/jackaal/aocmaps.threedd.com/aocparse/test.php on line 4

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.lazar/jackaal/aocmaps.threedd.com/aocparse/test.php on line 5

Quote:
<?
require ("actdb.php");
$query = "SELECT DISTINCT encid, name FROM combatant_table WHERE damage>0 AND ally='T'";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result)) {
$name[] = $row['name'];
$encid[] = $row['encid'];
}
?>
<select name="name" size="1" id="Combobox1">
<?
$option = "<option value=\"Please select a Category\">Please select a Category</option>";
for ($i = 0; $i < count($name); $i++) {
$option .= "<option ";
$option .= "value=\"$encid[$i]\">$name[$i]</option> \n";
}
echo $option;
?>
</select>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 06-04-2008, 02:53 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,024
Default Re: how to fill combobox with dynamic php variables ?

The options appear blank because you have no "option" echoed! See part in red i added in your post
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old 06-04-2008, 02:59 PM
Private
 
Join Date: Jun 2008
Location: Australia
Posts: 4
Default Re: how to fill combobox with dynamic php variables ?

Ah sensational. To be honest that particular line didn't quite click with me until I read it with your correction. Many thanks for your help. It would seem I have a long way to go!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old 06-04-2008, 04:12 PM
Private
 
Join Date: Jun 2008
Location: Australia
Posts: 4
Default Re: how to fill combobox with dynamic php variables ?

I do feel a little guilty asking these questions but after 2 days I'm considering that I may not be up for this. Anyway... I shall ask.

After progressive reading I've delved into building this over two php files. The end result should be to see the results of a table pertaining to a particular selection. It all goes well up until it is required to display the form and it appears blank.

Here are the files:

Code:
<?
require ("actdb.php");
$query = "SELECT DISTINCT name FROM combatant_table WHERE damage!=0 AND ally='T'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$name[] = $row['name'];
}

?>
<form action="encounter_table2.php" name="name" method="post">
<select name="name" size="1" id="name">
<?
$option = "<option value=\"Please select a Category\">Please select a Category</option> \n";
for ($i = 0; $i < count($name); $i++) {
$option .= "<option ";
$option .= "value=\"$name[$i]\">$name[$i]</option> \n"; }
echo $option;
?>
</select>
<input type="submit" value="submit" name="submit">
</form>
Which should all output to:

Code:
<?php
include 'actdb.php';
$toon_name=$_GET["name"];
$query  = "SELECT * FROM encounter_table WHERE name=" . $toon_name;
$result = mysql_query($query);
$name[] = $row['name'];

echo "<table border='1'>";
echo "<tr><th>Title</th><th>Start</th><th>End</th><th>Duration</th><th>Damage</th><th>ExtDPS</th><tr>";

    $escapedurl = htmlentities("combatant_table.php?encid=$row[0]", ENT_QUOTES);
    
    echo "<tr>" .
    "<td><a href='$escapedurl'>$name[1]</a></td>" .
    "<td>$name[2]</td>" .
    "<td>$name[3]</td>" .
    "<td>$name[4]</td>" .
    "<td>$name[5]</td>" .
    "<td>$name[6]</td>" .
    "</tr>";

echo "</table>";
?>
I think I'm at the point where my lack of experience has me totally stumped. Any help will be much appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old 06-04-2008, 04:30 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,024
Default Re: how to fill combobox with dynamic php variables ?

Your second listing is wrong:

<?php
include 'actdb.php';
$toon_name=$_GET["name"];
$query = "SELECT * FROM encounter_table WHERE name=" . $toon_name;
$result = mysql_query($query);
$name[] = $row['name'];

What's the part in red for (which, in any case, is wrong ) ?

I mean, you use SELECT * which means that you are selecting ALL columns from your table. At this point, you should have something like
$row = mysql_fetch_array($result);
$name = $row['name'];
$field2 = $row[field2'];
etc................................
}

So you put ALL the table data in arrays. Then you should echo the results in the table like

echo "<table border='1'>";
echo "<tr><th>Title</th><th>Start</th><th>End</th><th>Duration</th><th>Damage</th><th>ExtDPS</th><tr>";

$escapedurl = htmlentities("combatant_table.php?encid=$row[0]", ENT_QUOTES); // I don't know what you want to do here, neither where did you get $row[0] from

echo "<tr>" .
"<td><a href='$escapedurl'>$name</a></td>" .
"<td>$field2</td>" .
"<td>$field3td>" .
etc................
"</tr>";

echo "</table>";
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 04:26 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54