Is there a way to speed up this query. Its loading slow and its about 279 records. I’ve indexed the Language & id field in the data. Is there anything else I can do?
echo "<select name=language style='width: 136px;'>";
echo "<option value=$language selected=selected>-- Select --</option>";
$group1 = '<optgroup label=Common>';
$group2 = '<optgroup label=Alphabetically>';
$group = mysql_query("SELECT language, grouping, p_order FROM lang_list
WHERE grouping IN ('1','2') ORDER BY p_order");
while($row = mysql_fetch_array($group))
{
if ($row['grouping'] == '1')
{
$group1 .= '<option value="'.$row['language'].'">'.
$row['language'].'</option>';
}
else
{
$group2 .= '<option value="'.$row['language'].'">'.
$row['language'].'</option>';
}
$group1 .= '</otpgroup>';
$group2 .= '</otpgroup>';
echo $group1;
echo $group2;
echo "</select>";
}
Table
lang_list (
id int(8) NOT NULL auto_increment,
language varchar(75) NOT NULL,
grouping varchar(15) NOT NULL,
p_order varchar(15) NOT NULL,
PRIMARY KEY (id, language)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=280 ;
Just like in a book, page number of all chapters are given in the index because readers search by chapter, similarly for Mysql to process your queries faster, you need to index the fields which will be matched in the where condition. Index the fields which others have suggested here.