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!
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
The above SELECT will have the following result:
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

The above code results in:
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

The above code displays the following results in our browser:
Follow the example to see the actual records retrieved:

The code above displays the following 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:
- 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!
- 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
- Insert the cell PHP code in each cell to e displayed


Creating Dynamic length tables:
Creating dynamic length tables is easy. Simply create a table like the static length table
- This table has only 1 row, since the the length will be determined by the number of rows in the result set
- The cell contents are the same as a static length table
- The Table HTML dictates the looping

The results of the above static and dynamic table examples are shown in the browser like this:
next lesson - Forms, Overview
|