Forums

how to create drop down with db list

wiesiuwies 17 Feb, 2013
Hello!

I need create drop down databases list form external server. I create code but not working. PHP code i tested and they work but i don,t know how to join with drop down. Please help me with the code. For help big thanks

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Representative:</label>
    <select class="cf_inputbox" id="select_23" size="1" title=""  name="Rep">
    <option value="">Choose Option</option>

    <?php
     $con = mysql_connect("....", "...", "....");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_list = mysql_list_dbs($con);

while ($db = mysql_fetch_object($db_list))
  {
  echo $db->Database . "<br />";
  }

mysql_close($con);
    ?>

    </select>
  </div>
  <div class="cfclear"> </div>
</div>
wiesiuwies 18 Feb, 2013

Hi wiesiuwies,

Please see this FAQ

Bob




Hello Bob

I create thisbut not work

<?php
$options = array();
$options['driver']    = 'mysqli'; // Database driver name
$options['host']      = '...'; // Database host name
$options['user']      = 'root'; // User for database authentication
$options['password']  = '.....'; // Password for database authentication
$options['database']  = '.....'; // Database name



$db_list = mysql_list_dbs($con);

while ($db = mysql_fetch_object($db_list))
  {
  echo $db->Database . "<br />";
  }

// $options['prefix'] = ''); // probably not needed
$db = & JDatabase::getInstance($options);
$data = $db->loadObjectList();

?>


Thanks fo answer but in FAQ is how to connect to another base. I do not have this problem. My php code connect to server and show base list, it work perfect. Problem is how to show (list of bases)results in drop-down form or checkbox grup. How to connections this code with dropdown form

This is php code:
 <?php
     $con = mysql_connect("....", "...", "....");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_list = mysql_list_dbs($con);

while ($db = mysql_fetch_object($db_list))
  {
  echo $db->Database . "<br />";
  }

mysql_close($con);
    ?>


Then we see list of databses on server:

information_schema
adrian_test
ahorst
all_users
cdcol
irek
kelvin_brandes
michas
mysql
ott_dane
phpmyadmin
skorut
test
tomek
users
wodz_old
GreyHead 18 Feb, 2013
Hi wiesiuwies,

Sorry, I misunderstood your question.

Please see this FAQ

Bob

PS This should work:
<?php
$options = array();
$options['driver']    = 'mysqli'; // Database driver name
$options['host']      = '...'; // Database host name
$options['user']      = 'root'; // User for database authentication
$options['password']  = '.....'; // Password for database authentication
$options['database']  = '.....'; // Database name
// $options['prefix'] = ''); // probably not needed

$db = & JDatabase::getInstance($options);
$tables = $db->getTableList();
?>
This topic is locked and no more replies can be posted.