Simple prob, Pulling data from MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Simple prob, Pulling data from MySQL

Post by seeker2921 »

I need help on pulling my data from my database, I looked at all the functions for MySQL on the php.net site and found no help (mostly just confused me) I have a simple form that outs data into a table and I need to make a page that will display that data Thanks for your help
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

First you need to decide what data you want to display and write a SQL statement that will gather that data from the database. Then it's a case of looping through the result and outputting it into HTML tags. Have you made a start on the code because we can then help you a bit better.

Mac
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Post by seeker2921 »

All I have is the connection to the Database, I wasn't sure on what I needed to do in order to get the data out of the database..
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

First thing you need is an SQL SELECT statement, something like:

Code: Select all

SELECT field1, field2, field3 FROM my_table
would select information for field1, 2 and 3 from each row in my_table. I find phpMyAdmin useful for testing to see if the statement I'm writing works how I would expect. For more info on writing a SELECT statement (and lots of examples):
http://www.mysql.com/doc/en/SELECT.html

Once you've got that working then you can write your script, you start with [php_man]mysql_connect[/php_man](), then [php_man]mysql_select_db[/php_man]() and [php_man]mysql_query[/php_man](). Then you can use [php_man]mysql_fetch_assoc[/php_man]() to get the information for each row whilst looping through the result from mysql_query(). Finally you can add the HTML to format the display as needed.

If you make a start and have a go we'll help you as much as we can - a tutorial would likely be a good place to start (http://www.devshed.com).

Mac
Post Reply