-3

My code :

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

Print :

12

title1

title2

title3

name

ti1

ti2

ti3

y

tle1

tle2

tle3

86

mytitle1

mytitle2

mytitle3

This code work full buy for more values in $text , server has down !

1

1 Answer 1

0

Try to select all records in just one query, like this:

$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 />';
Sign up to request clarification or add additional context in comments.

1 Comment

resource(49) of type (mysql result) , but not echo titles !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.