Jump to content

Select * FROM table WHERE id = $array???


tommyda

Recommended Posts

is there a way to select * from a table where the row id matches any one of the numbers in an array?

 

I have a table called

 

Genres{ id, vlid, name }

 

And a table called

 

Movies(id, name, releasedate)

 

The genres are assigned to the movies using a the following table

 

Assign{ vlid,typeid, type }

 

What i want to do is select all the movie id;s from the assign table then pull the relevant movies using the vlids.

 

I do have a function but I have a feeling its is poorly coded, plus it doesnt work very well.

 

MoviesByAssign("genre", 1, 0, 30); should pull the first 30 movies assigned to the genre id "1"

 

 

<php
function MoviesByAssign($type, $typeid, $start, $limit){

$moviesingenre = array();
$result = mysql_query("SELECT vlid FROM assign WHERE type ='$type' AND typeid='$typeid'")or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo $row['vlid'].'-';
   $moviesingenre[] = $row['vlid'];
}

$result = mysql_query("SELECT * FROM videolistings ORDER BY releasedate DESC LIMIT $start, $limit");

$output='';

while($video = mysql_fetch_array($result)) {
   if(in_array($video['id'], $moviesingenre)) {
                $date = date("2/m/Y",$video['releasedate']);
             $num = GetMovieRating($video['id']);
             $expl = explode('-',$num);
                $round1 = round($expl[0],1);
	$rounded = round($expl[0]);
	if(empty($video['img'])){$img= $baseurl.'/images/x.gif';}else{$img= $video['img'];};
     $output.= '
     <div class="lholder">
     <a href="'.$baseurl.'/videos/'.$video['slug'].'_'.$video['id'].'" title="'.ucwords($video['name']).'">
     <img class="limg" src="'.$img.'" border="0"/></a>
     <div class="linfo">
     <a href="'.$baseurl.'/videos/'.$video['slug'].'_'.$video['id'].'" title="'.ucwords($video['name']).'"><strong>'.ucwords($video['name']).'</strong></a>
     <ul class="linkrow">
     <li>Release Date: '.$date.'</li>
     <li> Rating:
     <strong>'.$round1.'</strong> / 5  ('.$expl[1].' Votes) <br/><img src="'.$baseurl.'/img/stars_'.$rounded.'.gif"/></li></ul></div></div>';
  
   }//END IF

};//ND WHILE
return $output;

};//END FUNCTION

?>

 

Can anyone please help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.