Jump to content

Add an image to Table from Results


cortez

Recommended Posts

Hello all

Can anyone help me with this script I'm working on.

It's from the tutorial for setting up a searchable database.

http://www.devshed.com/c/a/PHP/Creating-a-Searchable-Inventory-System-Setting-Up-Your-Database-and-User-Interface-continued/

I was hoping I could just call the appropriate image path and dump it in on the results page only. 

<?php
				$r_html				= NULL;
				$r_row_count	= 0;

				# using helper function, run query and retrieve raw results
				$db_results	= $search->get_search_results();

				# if results have not been returned, display error message
				if ( !is_array( $db_results ) || count( $db_results ) == 0 ) {
					$r_html	.= 'No results were found for the search criteria you specified. Please try again.';

				# if results have been found, output them properly
				} else {
					$r_html	.= 'Your search returned the following results: <br><br>';
					$r_html	.= '<table width="100%">';
					$r_html	.= '<tr>';
					$r_html	.= '<th>' . $search->get_header_html( 'Category', 'pc_categories.name' ) . '</th>';
					$r_html	.= '<th>' . $search->get_header_html( 'Title', 'pc_sub_categories.name' ) . '</th>';
					$r_html	.= '<th>' . $search->get_header_html( 'Time Period', 'pc_manufacturers.name' ) . '</th>';
					$r_html	.= '<th>' . $search->get_header_html( 'Name',		'pc_parts.name' ) . '</th>';
					$r_html	.= '<th>Description</th>';
					$r_html	.= '</tr>';

					# for each result found, return a table row
					foreach ( $db_results as $db_result ) {

						# using row count, determine appropriate CSS class
						$l_css_class	= ( ++$r_row_count % 2 == 1 ) ? 'odd' : 'even';

						# output table row of results
						$r_html	.= '<tr class="' . $l_css_class . '">'
//I tried to add in the image path here	
                                                        $r_html	.= '<td>' . "<img src=\"" . $db_result['part_name_image'] . "\">"; '</td>';
						$r_html	.= '<td>' . $db_result['category_name']		. '</td>';
						$r_html	.= '<td>' . $db_result['sub_category_name']	. '</td>';
						$r_html	.= '<td>' . $db_result['pc_manufacturer_name']	. '</td>';
						$r_html	.= '<td>' . $db_result['part_name']		. '</td>';
						$r_html	.= '<td>' . $db_result['part_description']	. '</td>';
						$r_html	.= '</tr>';		
					} # END for each result

					# close table
					$r_html	.= '</table>';

				} # END if results found

				# display results HTML
				echo $r_html;
			?> 

Is this possible to call up the image here or will I need to include the path to the image in the previous search functions as well?

If this is an easy fix I'll be through the roof!

Cheers

Curt

Link to comment
https://forums.phpfreaks.com/topic/148164-add-an-image-to-table-from-results/
Share on other sites

I already have the image path in my database and am able to call it up and display no problem on a simple trial.

My problem here is pulling it up into this table.

I'm sure it's my syntax on this line.

 $r_html	.= '<td>' . "<img src=\"" . $db_result['part_name_image'] . "\">"; '</td>';

Not 100% sure how to code this.

On a direct query I am able to pull it up like so with the picture being a link

echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ; 

Thanks for your suggestions.

So I found a section in the config file that I had to set up to get access to the path in my database I wanted to select and have it showing up in the correct cell. I managed to get my picture to upload using this synatx

 $r_html.= '<td><img src=\'' . $db_result['part_image']  . '\' border=0 alt=\'' . '\'></td>'; 

This issue is solved.

Thanx

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.