0

I'm trying to create a dropdown list with items from the mysql database. The problem is that my list is empty. I looked around but I could not find a solution.

 $q = $db->getQuery(true);

$q->select('#__peaks.peak_name');
$q->from($db->quoteName('#__peaks'));

$db->setQuery($q);
$result = $db->loadColumn();


echo "<select name='peak_name'>"; 
echo "<option size =30 ></option>";
while($row = mysql_fetch_array($result)) 
{        
echo "<option value='".$row['peak_name']."'>".$row['peak_name']."</option>"; 
}
echo "</select>";

Where am I wrong? Please help.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
Midhat
  • 45
  • 10
  • PHP I guess? First do **NOT** use mysql* functions (https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189) and use prepared statements (https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php/60496#60496). – Nic3500 Nov 11 '17 at 16:17
  • Then if you see nothing, it means $result is empty, nothing to while on. Check your query, check your data. – Nic3500 Nov 11 '17 at 16:19
  • When I try echo $result i have list from mysql – Midhat Nov 11 '17 at 16:30
  • You are mixing Joomla (loadColumn) with regular PHP (and the wrong at that, reference mysql_fetch_array). Stick to Joomla or user native PHP, but do not mix them. Look at the Joomla documentation for examples. – Nic3500 Nov 12 '17 at 00:20

0 Answers0