Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Optimieren Sie while und SQL in foreach

Versuchen Sie, alle Datensätze in nur einer Abfrage auszuwählen, etwa so:

$text = '12-name-y-86';
$array = explode('-', $text);
$array = "'" . implode(',', $array) . "'";
$sql = mysql_query("SELECT * FROM `table` WHERE `pid` IN (' . $array . ') ORDER BY `id` LIMIT 3");
while($row = mysql_fetch_array($sql)) {
    echo $row['title'];
    echo '<br />';
}
echo '<br /><br />';