Forum Moderators: coopster
I am using this:
$sql = "SELECT * from products WHERE pSection=7 ORDER BY RAND() LIMIT 0,3";
Which is fine, it pulls products from pSection 7 fine. But I want it to pull from several sections at once. I tried making an array like this:
$randpsections = array("9", "10", "11", "12");
and then
$sql = "SELECT * from products WHERE pSection=$randpsections ORDER BY RAND() LIMIT 0,3";
But I get an error.
Obviously I have very limited PHP knowledge so would appreciate any help.
Thanks
Parse error: parse error, unexpected ']' in /home/sites/www.example.com/web/test.php on line 33
which is this line:
<?php $sql = "SELECT * from products WHERE pSection=" . $randpsections[mt_rand(0,count($randpsections)-1] . " ORDER BY RAND() LIMIT 0,3";
Don't see the error - any suggestions?
The rest of the code, in case it is relevant, is below.
<?php
$randpsections = array("9", "10", "11", "12");
$sql = "SELECT * from products WHERE pSection=" . $randpsections[mt_rand(0,count($randpsections)-1] . " ORDER BY RAND() LIMIT 0,3";
$result = mysql_query($sql) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
$name = $newArray['pName'];
$image = $newArray['pImage'];
$doit = $newArray["pDescription"];
$max=70;
$modstr=((strlen($doit)>$max)?substr($doit,0,$max) . "..." : $doit);
echo "stuff here";
}
@mysql_free_result($queryprod);
?>
$randpsections = array("9", "10", "11", "12");
$sql = "SELECT * from products WHERE pSection IN (" .implode(",", $randpsections). ") ORDER BY RAND() LIMIT 0,3";