1

I've noticed several threads on here and through Google searches on how to do this, but I need something a little more specific to my needs in order to execute it as I am pretty new to PHP. Hopefully someone can help.

I have a page with 5 Divs (lets just call them 1-5). I have a MYSQL database named 'Users' with columns 'ID' (primary key), 'Member', 'Review' and 'location'.

I would like to randomly populate each Div with rows from this DB and show information from the above mentioned columns.

Can anyone give me guidance on where to begin, or possibly give me sample code that meets the above criteria?

Thanks so much for any help.

3
  • What have you tried? What part are you getting stuck on? For example, do you know how to query your database? Do you know how to iterate over a list of database results? Do you know how to write text to the page with PHP? (javscript shouldn't be necessary unless you need it to be interactive or want to use ajax to do live updates). Commented Aug 23, 2012 at 19:46
  • Sorry for lack of detail. I'll eventually get better better at asking educated questions. I am very new to this process, so I havent tried anything that has been close to working. I do know how to query my Database, but not with PHP. I also do not know how to write the PHP back to the page and make it loop through each DIV Commented Aug 23, 2012 at 19:58
  • First, make a PHP page that would populate one of your divs. Like... pretend one of your divs is a page in its own right. I'd try googling "PHP MySQL query" and see if you can work your way through a tutorial. Just note that you probably want to find one that uses the mysqli class, because the older functions are getting canned. Commented Aug 23, 2012 at 20:07

1 Answer 1

2

Here is a general answer:

1) in PHP establish a connection to you database. something like this:

$connection = mysql_connect($host,$username,$password);

2) query the database:

mysql_select_db($schema, $connection);

$result = mysql_query("Put your sql query here...");

3) loop over the results and echo them to the screen,

while($row = mysql_fetch_array($result))
{
    echo $row['mysql_column_name_here'];
}
1
  • This helps to get me started. Thanks! Commented Aug 24, 2012 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.