PHP Dropdown

sharataka 22 Dec, 2010
Hi,

I need help creating a dropdown using PHP. I tried using another thread as a resource, but am not sure how to apply it (http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=2&t=19902&p=60700&hilit=php+dropdown#p60700). I am using an article from the Chronoforms book and am trying to adapt it for my needs (http://greyhead.net/chronoforms/using-php-to-create-select-dropdowns).

The code is below:

<?php 
 
@ $db = new mysqli('MYLOCALHOST', 'USERNAME', 'PASSWORD', 

'DATABASE');

if (mysqli_connect_errno()) {
  echo 'Error: could not connect.';
exit;
}

else{
  echo 'Successful connection.';
}

$query="
SELECT `Index` , `Retailer`
FROM `Product Catalog` 
WHERE `Amount` >0
ORDER BY `Retailer` ASC 
LIMIT 0 , 30 
";

$db->setQuery($query);
$options = $db->loadAssocList();
foreach ( $options as $o ) {
  echo "<option value='".$o[Index]."'>".$o[Retailer]."</option>";
}

 ?> 


I am able to set up the connection with MySql but am not sure how to finish with the dropdown. Do I need to add html or will just the php code do? Additionally, I have been playing around with this on a separate file. Where do I place this code in Chronoforms?

Thanks,
Sharat
GreyHead 22 Dec, 2010
Hi Sharat,

You seem to have hacked the code in the article rather dramatically. If you put back the Joomla! $db definition and remove your own version and also put back the rest of the <select> tags then the code should work.

It goes into the Form HTML box.

Bob
This topic is locked and no more replies can be posted.