Forums

read Database + dropdown

michaelc 02 Sep, 2008
Hello there... I'm currently working on a form that needs to read a few joomla tables and then populate a dropdown box in the form. I've got chronoforms + mambot installed and working but I keep on getting an empty dropdown... I believe the sql and php code is correct and was wondering if chronoforms can perform this task? or should i get chrono connectivity? (i know nothin abt chrono connectivity)
Max_admin 02 Sep, 2008
Hi michaelc,

Chronoforms will be fine because you are populating a dropdown and not publishing a big records list in a full page, if you SQL is fine then it should work, how do u know ur code works ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
michaelc 02 Sep, 2008
Hello again. thanks for the quick reply. Well the code is here. I'm pretty sure it should work but it showing a blank drop down which is weird.


<?php

// connection works for sure, i just erased the ser/pass etc from here
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

mysql_select_db($db) or die ("Unable to select database!");

$query = "SELECT a.title FROM jos_content a, jos_categories b, jos_sections c
WHERE a.sectionid = b.id AND b.section = c.id AND c.title = 'Engine'";


$result = mysql_query($query);  
?>

<form method="post" action="eng.php">
  <table>
    <tr>
      <th>Event Name:</th>
      <td><select name="carList">

<?php
    while ($row = mysql_fetch_array ($result))
    {  
?>
 <option value="<? echo $row["title"]; ?>">

 </option>
<?php
    }
?>
    </td></tr>
    <tr>
      <th>Organization Name</th>
      <td><input type="text" name="orgName" size="25" /></td>
     </tr>
     <tr>
      <th colspan ="2" align="center"><input type="submit" value="Submit"/></th>
    </tr>
  </table>
</form>
<?php
mysql_close($connection);
?> 
Max_admin 02 Sep, 2008
Hi,

well, using this code inside Joomla is not recommended, you should use the Joomla DB handler to do this, search the forums for setQuery, you will see how its easy to write your SQL and execute it and get an objectlist with all your data and you should not care for connections!๐Ÿ™‚ I think this is why it doesn't work! ah, and remove form tags also!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
michaelc 02 Sep, 2008
Oh oh- well ok then, i'll look up the setQuery now. Looks like i have to restart from the start:( Thanks again-
Max_admin 02 Sep, 2008
No restrat, you replace all your PHP code with 3 lines, you already have the SQL code, this will be easier for you now and later๐Ÿ˜‰
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
michaelc 02 Sep, 2008
Oh ok- thanks for the heads up- btw do we need to include the form tag in CF or is it redundant?
michaelc 02 Sep, 2008
Something is still wrong and i can't find it...

<?php
global $database;
$sql = "SELECT a.title FROM jos_content a, jos_categories b, jos_sections c
WHERE a.sectionid = b.id AND b.section = c.id AND c.title = 'Engine'";

$database->setQuery( $sql );
$rows = $database->loadObjectList();
?>
  <table>
    <tr>
      <th>Name:</th>
      <td><select name="carList">
<?php
foreach($rows as $row) {
 echo "<option value='".$row->title."'></option>";
}
?>
    </select></td></tr>



What I'm looking for is to populate just the title into the dropdown. The error message i'm getting is this:
Fatal error: Call to a member function setQuery() on a non-object in ..............plugins\content\chronocontact.php(207) : eval()'d code on line 7
Max_admin 02 Sep, 2008
Hi michael,

try to replace
global $database;
with :

global $mainframe;
	$database =& JFactory::getDBO();


since you have Joomla 1.5 I guess.

let me know!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
michaelc 05 Sep, 2008
Hi there- Well I dunno really know the joomla stylez syntax so i had to go back to php and i found the problem. i had missed a line between the <option> tags and now its working like a charm... Thanks heaps dude
This topic is locked and no more replies can be posted.