The Interface
Quick Start Guide
Creating Pages
Opening and Editing Pages
Uploading and Managing Files
Menu Display System
Site Templates
Shopping Cart & eCommerce
Event Calendar
eNewsletter Module
Database Table Manager
Secure Users
Site Data Tables
Photo Album
Site Statistics
Blog Manager
Webmaster Menu
Custom Web Forms
Custom PHP Includes
Programming structure
Custom HTML and PHP within the Page Editor
Custom Shipping Include
Custom Gateway Included
Custom Invoice Include
Custom Template Include
Custom Detail Page Include
Resources for Help
Search Engine Optimization
Useful Web Resources
Default Style Sheet File
Built-In Javascript Functions
Frequently Asked Questions (FAQs)
Online Users Manual Search Manual for:  
Custom PHP Includes
Custom Detail Page Include

When creating searches through the database table manager, you have the option to define a custom PHP include for displaying the search result details. In these cases it is imperative that you are familiar with mySQL functions and how they are utilized within PHP. The included example script shows how to take the values passed from the initial search results and display them to the screen for the “detail” view. It is very basic in nature but provides a template for creating very robust display sets.

Pay particular attention to the commented code as it provides detailed explanation of what should be changed to utilize this script with a working site.

Let’s write our script:

<?php

#######################################################
### DETAIL DISPLAY INCLUDE EXAMPLE
### FOR DATABASE SEARCH RESULTS DETAIL PAGE
#######################################################


// ECHO JAVASCRIPT USE FOR BACK BUTTON DISPLAY
// ---------------------------------------------------

echo "\n\n";
echo "<SCRIPT LANGUAGE=Javascript>\n\n";
echo " function initial_results() {\n";
echo " window.document.BACK.submit();\n";
echo " }\n\n";
echo "</SCRIPT>\n\n";

// ECHO SCREEN HEADER
// ---------------------------------------------------

echo "<CENTER><INPUT TYPE=BUTTON VALUE=\" << Back \" ";
echo "onclick=\"initial_results();\"";
echo " CLASS=FormLt1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";

echo "<INPUT TYPE=SUBMIT VALUE=\" New Search \“
CLASS=FormLt1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n";

echo "<INPUT TYPE=BUTTON VALUE=\" Print Record \"
onclick=\"javascript: window.print();\" CLASS=FormLt1>\n";

echo "</FORM><BR>\n\n";


// PULL DATA FROM DATA-TABLE BASED ON SEARCH CRITERIA BY
// CREATING SQL SEARCH STRING
// ---------------------------------------------------

$result = mysql_query("SELECT * FROM $TABLE_NAME");
$numberFields = mysql_num_fields($result);
$numberFields--;

$detail_display = "";
for ($x=0;$x<=$numberFields;$x++) {
$fieldname[$x] = mysql_field_name($result, $x);
$fieldname[$x] = strtoupper($fieldname[$x]);

$tmp = "DISPLAY_".$fieldname[$x];
if (${$tmp} == "D" || ${$tmp} == "B") {
$detail_display .= "$fieldname[$x], ";
}
}

$str_tmp = strlen($detail_display);
$str_new = $str_tmp - 2;

// Remove extra comma in string
$detail_display = substr($detail_display, 0, $str_new);

// Remove slashes from "posted" transfer
$SQL_SEARCH = stripslashes($SQL_SEARCH);

// Replace previous "selected fields" with Detail fields
$tmp = "SELECT $detail_display, AUTO_SECURITY_AUTH FROM";
$SQL_SEARCH = ereg_replace("SELECT (.*) FROM", "$tmp", $SQL_SEARCH);

// Clear Security Check for Record Owner
$EDIT_SECURITY_CHECK = "";

// ---------------------------------------------------
// PERFORM ACTUAL SQL QUERY FOR RECORD DATA
// ---------------------------------------------------

$result = mysql_query("$SQL_SEARCH");

/// ---------------------------------------------------
// DETERMINE WHICH ROW TO USE BASED ON "row_count" VARIABLE
// PASSED TO THIS SCRIPT IN PREVIOUS STEP (INITIAL RESULTS)
// ---------------------------------------------------

$i = 0; // Reset Row Counter to zero; DO NOT DELETE

// Loop through each record from query
while ($row = mysql_fetch_array($result)) {

// If this is our record, display it now

if ($i == $ROW_NUM) {

// ---------------------------------------------------------
// DEFINE FIELD VALUES INTO A VARIABLE TO "ECHO"
// TO THE SCREEN
// ---------------------------------------------------------

// Is there an MD5 Security Code for this?
$SECURITY_CODE = $row[AUTO_SECURITY_AUTH];

// What field name is in the image field?
$IMAGE_FILENAME = $row[AUTO_IMAGE];

// Trim off extra spaces that may be in filename data
$IMAGE_FILENAME = rtrim($IMAGE_FILENAME);
$IMAGE_FILENAME = ltrim($IMAGE_FILENAME);

#############################################################
#############################################################
// The following Field names are just "made up"... Depending
// on what youname your field names within the table,
// modify the code to reflect thatdata.
// REMEMBER: Field names are case sensitive.
// There are only three field names represented here, of
// course, you mayhave as many as needed, so add away
// based on your table structure.
#############################################################
#############################################################

$FIRST_NAME = $row[FIRST_NAME];
$LAST_NAME = $row[LAST_NAME];
$EMAIL_ADDRESS = $row[EMAIL_ADDRESS];

// ---------------------------------------------------------
// NOW ECHO OUR "DISPLAY" TO THE SCREEN
// ---------------------------------------------------------

echo "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0 ";
echo "WIDTH=85% ALIGN=CENTER ";
echo "STYLE='border: 1px inset black; background: #EFEFEF;'>\n";
echo "<TR><TD ALIGN=LEFT VALIGN=TOP CLASS=text bgcolor=#EFEFEF>\n";
echo "<img src=\"$doc_root/images/$IMAGE_FILENAME\" align=left ";
echo "border=1 vspace=2 hspace=2>\n";

echo "$FIRST_NAME $LAST_NAME<BR>\n";
echo "$EMAIL_ADDRESS<BR><BR>\n";
echo "</TD></TR></TABLE>\n";

// ---------------------------------------------

} // End If ROW_NUM is found

// ---------------------------------------------

$i++; // DO NOT DELETE; Increment Row counter

} // End While Loop

// -----------------------------------------------
// End Custom Display Script Example
// -----------------------------------------------

?>