Msql select

I am making a forum. I am trying to select about twenty records from a table… basically building a page which lists the various posts and their titles.

I want to do something like this …

SELECT FROM listposts WHERE recordnumber=126 or recordnumber=437 or recordnumber=174 or recordnumber=4321 or recordnumber=46 or recordnumber=39

So I want to select all records which match a list of recordnumbers. Is there a special way I can do this?

I do not have great experience with msql so sorry or any ignorance

I basically want to select all records which match an array eg

$test=Array(17,145,14);

$result = mysql_query(“SELECT postnumber,timedate FROM list WHERE postnumber=‘$test’”);

Sure. :slight_smile:


SELECT this FROM that WHERE other IN (1, 2, 3, 4)

He’ll need to use [fphp]implode[/fphp]


$s = $pdo->prepare("
  SELECT postnumber, timedate 
  FROM list 
  WHERE postnumber IN (".implode(',',$test).")
");

$s->execute();


PDO is prefered to the mysql (or mssql) function libraries.

If you got that list of record id’s from another query it’s faster to just nest the queries like this


SELECT postnumber, timedate
FROM list
WHERE postnumber IN (
  SELECT postnumber
  FROM ??....
)

Thanks everyone

Michael : The execute and prepare were not needed as the implode worked well on its own eg

$result = mysql_query(“SELECT postnumber,timedate,dream FROM list WHERE postnumber IN (”.implode(‘,’,$test).“)”);

You guessed correctly that the array comes from another select and I would need to nest selects