Jump to content

How would print retrieved records from this search in a simple formatted table


938660

Recommended Posts

 

<div align="center" id="content_div">

<table>

<form name="search_form" action="index.php" method="post"> <tr>

<th style="width: 175px;">Category:</th>

<th style="width: 175px;">Sub Category:</th>

<th style="width: 175px;">Manufacturers:</th>

<th style="width: 175px;">Keywords:</th>

</tr>

<tr>

<?php $search = new search(); ?>

<td>

<?php echo $search->get_search_field( 'Categories' ); ?>

</td>

<td>

<?php echo $search->get_search_field( 'Sub Categories' ); ?>

</td>

<td>

<?php echo $search->get_search_field( 'Manufacturers' ); ?>

</td>

<td>

<?php echo $search->get_search_field( 'Keywords' ); ?>

</td>

<td>

<INPUT type="submit" value="go"/>

</td>

</tr>

</form>

 

</body>

</html>

hi sorry im clueless. Im using an example which wasnt quite completed but i would like to modify the code and adapt it to my site once i discover how to output results in a table. Do you suggest me looking at a more easier example.

 

'Since we are creating several of these select menus to depend on another menu, we will also need to tell the “get_search_field” function whether a field is dependent upon itself, or another field.' - <<<i have a list of arrays also for these, not sure if u need them but below is the class.

 

 

<?php

class search {

 

function get_field_session_value( $p_search_field_name ) {

return $_SESSION[ 'search_' . $p_search_field_name ];

} # END get_field_session_value()

 

function get_search_field( $p_search_field_name ) {

$r_html = NULL;

 

# retrieve search field information from GLOBALS array

$f_search_array = $GLOBALS['search_array'][ $p_search_field_name ];

 

# check session for pre-set search field value

$f_input_value = $this->get_field_session_value( $p_search_field_name );

 

# retrieve any additional pre-set HTML attributes

$f_html_attributes = $f_search_array['html_attributes'];

 

# properly format field name before continuing

$f_search_field_name = str_replace( ' ', '_', $p_search_field_name );

 

# if field is of type select, then return a SELECT input field with all appropriate options

if ( $f_search_array['field_type'] == 'select' ) {

 

# open select tag

$r_html .= "<SELECT NAME='$f_search_field_name' ID='$f_search_field_name' $f_html_attributes /> \r\n";

 

# append (empty) "Any" option

$r_html .= "<OPTION value=''>Any</OPTION> \r\n";

 

# retrieve all appropriate OPTIONs from DB using specified query

# NOTE: replace placeholder "<<field>>" with appropriate parent-select-menu value if applicable

$db_result = mysql_query( str_replace( '<<field>>', $this->get_field_session_value( $f_search_array['parent_menu'] ), $f_search_array['populate_query'] ) );

if ( @ mysql_num_rows( $db_result ) ) {

while ( $db_record = mysql_fetch_assoc( $db_result ) ) {

 

# retrieve SQL values

$l_option_value = $db_record['value'];

$l_option_display = $db_record['display'];

 

# check to see if current option has been selected

$l_selected = ( $l_option_value == $f_input_value ) ? 'selected' : NULL;

 

# append OPTION tag

$r_html .= "<OPTION value='$l_option_value' $l_selected>$l_option_display</OPTION> \r\n";

 

} # END for each result

 

} # END if results found

 

# close select tag

$r_html .= "</SELECT> \r\n";

 

# if field is of type text, then simply return a TEXT input field

} else {

 

# return a text input field

$r_html .= "<INPUT TYPE='text' NAME='$f_search_field_name' ID='$f_search_field_name' VALUE='$f_input_value' $f_html_attributes />";

 

} # EBD 'field_type' check

 

# return HTML

return $r_html;

 

} # END get_search_field()

 

function set_field_session_value( $p_search_field_name, $p_search_field_value ) {

$_SESSION[ 'search_' . $p_search_field_name ] = $p_search_field_value;

} # END set_field_session_value()

 

} # END class search

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.