Where your adventure begins
Full Service Web HostingNetObjects Fusion 7 Websites Portal



On This Page

SELECTS returning 1 record

SELECTS -- many records

Display in Table Format

All the Examples on this page can be found in the php sample site

Once you have connected to the server and opened the database, you'll want to get to your data!

In This Tutorial

MySQL--Getting Started

SELECT Statements


On All Forms




Combo Boxes

To get data from a database, you SELECT it using the mysql_query() function.

$result = mysql_query( "SQL query here", optional dbconnection here);

Single SELECT Statements

"Single SELECTs" are select statements that return only 1 row

The value(s) returned from mysql_query() are stored in a "result set" variable. Here we named is $result

SELECt that returns only 1 record from table

The above SELECT will have the following result:

Results of above PHP code

Remember that the results are not displayed and are not usable as they are stored now. We will have to retrieve the information and place into variable to manipulate it

One way to display PHP code

The above code results in:

What the user will see

Other Examples of single SELECT statements

// counts all the rows in the table and names the count "counter"
select count(*) as counter from table;
// returns the userid associated with DixieLee
select distinct userid from table where username="DixieLee";

Multiple SELECT Statements

These SELECTs are statements that return more than one row are called Multiple SELECTS

select name, nickname, email, hits, bestgfbuddy
       from gfpets
       order by name";

In our database example, we see how this works

SELECT statement that retrieves more than 1 record/row from table

The above code displays the following results in our browser:

Results of PHP code
Follow the example to see the actual records retrieved:

How do I get to look at all these rows?

The code above displays the following results:

Resuls and diplay results

Displaying Data in Table Form

  • There are many ways that PHP can format data into a table structure, but remember, you still want to use the elegance of Fusion! The following is one simple example. You can think of many others that will work just a nicely
  • In the .nft example file, the table is drawn out first in NOF, then a table counter is initialized. On each row the field is referenced and the last cell on each row is an increment to the counter. PHP evaluates left to right, top to bottom, so it will fill the cells with information, then increment the counter and go down to the next row...
  • You can also easily use NOF for specialized formatting, background and table structure
  • You could also write the HTML code in PHP and do the formatting within PHP instead of using NOF's formatting if you would like
  • PHP can be embedded at the table level or the cell level
Static Length Tables:

Refer to the example in the .nft template and the graphics below:

  1. Create your table. In Fusion, perform all background, color, column, text, and cell formatting. remember, to let Fusion handle as much of the coding as possible. This keeps your PHP and extra code to a minimum!
  2. Insert Table HTML to begin counter (This is useful for static length tables. The first table in our example has 6 rows in it. We want to print only 6 records due to this limit).  This is useful if you want 'x' number of records per page to be displayed
  3. Insert the cell PHP code in each cell to e displayed

Dynamic tables.....

Creating Dynamic length tables:

Creating dynamic length tables is easy. Simply create a table like the static length table

  1. This table has only 1 row, since the the length will be determined by the number of rows in the result set
  2. The cell contents are the same as a static length table
  3. The Table HTML dictates the looping

How to get information easily into tables using arrays w/o having to create the table in HTML

The results of the above static and dynamic table examples are shown in the browser like this:


next lesson - Forms, Overview

View the PREVIOUS page in this tutorial

Return to the TOP of this page

View the NEXT page in this tutorial

|  Fusion  |  Web Design  |  Hosting  |  Resources  |  gotFusion Store  | 

Problems with this page?  

All content copyright © 2002 gotFusion LLC.  The name gotFusion and the gotFusion ® logo are registered trademarks of gotFusion LLC
Copyright, legal notice & privacy statement