# Query Problem - Query and Rand help

**URL:** https://forum.kirupa.com/t/query-problem-query-and-rand-help/326843
**Category:** Uncategorized
**Created:** [January 16, 2012, 7:00am UTC](https://forum.kirupa.com/t/query-problem-query-and-rand-help/326843 "2012-01-16T07:00:43Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![LordNecro](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@LordNecro](https://forum.kirupa.com/u/LordNecro)
#### Post date: [January 16, 2012, 7:00am UTC](https://forum.kirupa.com/t/query-problem-query-and-rand-help/326843/1 "2012-01-16T07:00:43Z")

</div>

Hey guys, i’m back. i’ve had a small break from learning php and it has been the death of me.

I am working on a small project to learn and i cannot get it working. doing a small fake dvd website, which will allow me to edit movies/members/display movie info.

I am having trouble writing a query for the front page. Here is the problem: My database has a table, each row with an auto id. It also has a rental period id. I wish to write a script to select all rows with a rental period id of “3” and then add them to an array, select 3 of them from random and display them.

Here is what I have so far, but i am getting resource id’s

```php

<?php
                    $query = "SELECT `movie_id` FROM `movies_table` WHERE `rentalperiod_id` = '3' ";
                    $result = mysql_query($query);
                    print $result;
                    //$num = mysql_num_rows($result);
                    //if ($num > 0) 
                    {
                        $id_array = array();
                        while ($row = mysql_fetch_assoc($result)) 
                        {
                            $id_array []=$row["movie_id"];
                        }
                        $query = "SELECT `movie_url` FROM `movies_table` WHERE `movie_id`=".$id_array[rand(0, (count ($id_array)-1))];
                        $result = mysql_query($query);
                        $row = mysql_fetch_assoc($result);

                    }

```
