# Grab a random row from a database with a speciality

**URL:** https://forum.kirupa.com/t/grab-a-random-row-from-a-database-with-a-speciality/204586
**Category:** programming
**Created:** [October 21, 2006, 4:10am UTC](https://forum.kirupa.com/t/grab-a-random-row-from-a-database-with-a-speciality/204586 "2006-10-21T04:10:35Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Dog\_E](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dog_e/32/360_2.png) [@Dog\_E](https://forum.kirupa.com/u/Dog_E)
#### Post date: [October 21, 2006, 4:10am UTC](https://forum.kirupa.com/t/grab-a-random-row-from-a-database-with-a-speciality/204586/1 "2006-10-21T04:10:35Z")

</div>

Hello everyone,

Me and a friend of mine have started a project (no school involved, all personal) and it is functioning really well. I thought about the ideas, designed visuals and he did the PHP and MYSQL programming.

He is away now, and currently don’t have a Internet connection where he can sit down and work on PHP so I thought about couple of ideas, even though I don’t really know how PHP and MYSQL connects I tried to implement them and since I am studying a Computer Engineering, I thought the idea should be similar but the experience.

So here is my problem:

There is a table named **‘comments’**. It has rows which has fields of **id, comment, author, super**

So on the page, which is index.php I want to randomly pick a row ‘which’ has a **super = 1**. If it is 0, it is not going to be in the list of possible items.

There are 3 files.

**db.php** - \> Connects to database and includes information like database name, password and stuff like that.

**theme.php** - \> The theme basically

**index.php** - \> Connects to database using **db.php** and then uses lots of calculations to print it into the page using the theme.

My question is, what kind of function would I write and on which of the files would I do it?

To remind you, it is going to look for a random item in ‘comments’ row which has a field \*\*super \*\*that equals to **1**.

I’d be glad if you could help me on this.

Thanks,

Dog-E
