Link to home
Start Free TrialLog in
Avatar of derek2277
derek2277

asked on

Displaying MySQL search results in a table; Sphider script

Hi,

I have modified the sphider web spider script (http://www.sphider.eu/) to spider websites, download images, and place the location of the image into the database.  Now, I am trying to display the results in a table that is dynamically created per the number of results found.  I am looking for the results page to display up to 20 images per page and look like so:
--------------------
|IMG|IMG|IMG|IMG|
--------------------
|IMG|IMG|IMG|IMG|
--------------------
|IMG|IMG|IMG|IMG|
--------------------
|IMG|IMG|IMG|IMG|
--------------------
|IMG|IMG|IMG|IMG|
--------------------
page 1 of X

Attached code snippet explanations:

The first snippet of code is most of the search_results.php script.  Using this snippet displays all of the results correctly in a table, but only in one column.

The second snippet is more of what I am looking for, but I cannot get it to work correctly.  The problem is that the script will repeat the images and then add another image to the result (as shown in the attached image sphider.png).  Then there is another huge problem with this snippet... the amount of results that are displayed seem to be controlled by the number of search results found; meaning, if there are 70 results found the script will repeat the images 70 times, plus one more, for a total of 71 images displayed (as seen in attached image sphider2.png).  Do any of you php gurus out there know of a fix to this problem?

This is my first post, so please bear with me and let me know if you need more information.

I look forward to your responses and thank you very much to anyone who can help me with this question!

Thank you!
displays results in one column:
 
<?php 
extract($search_results);
?>
 
<?php if ($search_results['did_you_mean']){?>
	<div id="did_you_mean">
	<?php echo $sph_messages['DidYouMean'];?>: <a href="<?php print 'search.php?query='.quote_replace(addmarks($search_results['did_you_mean'])).'&search=1'?>"><?php print $search_results['did_you_mean_b']; ?></a>?
    </div>
<?php  }?>	
 
<?php if ($search_results['ignore_words']){?>
	<div id="common_report">
	<?php while ($thisword=each($ignore_words)) {
		$ignored .= " ".$thisword[1];
	}		
	$msg = str_replace ('%ignored_words', $ignored, $sph_messages["ignoredWords"]); 
	echo $msg; ?>
    </div>
<?php  }?>	
 
 
<?php if ($search_results['total_results']==0){?>
	<div id ="result_report">
		<?php 
		$msg = str_replace ('%query', $ent_query, $sph_messages["noMatch"]);
		echo $msg;
		?>
	</div>
<?php  }?>	
 
 
<?php if ($total_results != 0 && $from <= $to){?>
	<div id ="result_report">
	<?php  
	$result = $sph_messages['Results'];
	$result = str_replace ('%from', $from, $result);
	$result = str_replace ('%to', $to, $result);
	$result = str_replace ('%all', $total_results, $result);
	$matchword = $sph_messages["matches"];
	if ($total_results== 1) {
		$matchword= $sph_messages["match"];
	} else {
		$matchword= $sph_messages["matches"];
	}
 
	$result = str_replace ('%matchword', $matchword, $result);	 
	$result = str_replace ('%secs', $time, $result);
	echo $result;
	?>
	</div>
<?php  }?>	
 
 
<?php if (isset($qry_results)) {
 
?>
 
 
<div id="results">
<table><tr>
<!-- results listing -->
	<?php foreach ($qry_results as $_key => $_row){
		$last_domain = $domain_name;
		extract($_row);
		
?>
		<td><div class='resultItemWrapper'>
		<div class="resultImg"><?php if(!empty($imgpath)) { ?>
			<div align="center"><a href="/details.php?id=<?=$link_id;?>"><img src="/dldimg/<?=$imgpath;?>" width="100" height="100" border="0"></a>
			  <?php } ?>
		    </div>
		</div>
		</div></td>
	<?php  }?>
    </tr></table>
 </div>
<?php }?>
 
altered snippet of above that displays results in a table, but repeats the image, and then ads an additional image per result found:
 
<div id="results">
<table>
<!-- results listing -->
	<?php foreach ($qry_results as $_key => $_row){
		$last_domain = $domain_name;
		extract($_row);
		
		$tmp_cnt = 0;
		$per_row = 4;
		for($i=0;$i<=$total_results;$i++)
			{
			echo (($tmp_cnt %$per_row == 0) ? '<tr>' : '').
			"<td><a href=\"/details.php?id=$link_id\"><img src=\"/dldimg/$imgpath\" width=\"100\" height=\"100\" border=\"0\"></a></td>"
				.((++$tmp_cnt %$per_row == 0) ? '</tr>' : '');
			}
		echo ($tmp_cnt %$per_row !== 0)
			? '<td colspan="' .($per_row - ($tmp_cnt % $per_row)). '">&nbsp;</td></tr>'
			: ''; 
		
?>
 
	<?php  }?>
</table>
 </div>
<?php }?>

Open in new window

sphider.png
sphider2.png
ASKER CERTIFIED SOLUTION
Avatar of bansidhar
bansidhar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derek2277
derek2277

ASKER

Hi bansidhar,

Thanks for the response.  Almost there! I included the resulting code and an image of the output.  As you can see the code creates a new row for the first result, then works correctly for each result after the first result.  Any ideas on how to fix this?

Thanks a lot!
<div id="results">
<table><tr>
<!-- results listing -->
<td>
<div class='resultItemWrapper'>
	<div class="resultImg">
    	<div align="center"><a href="/details.php?id=19449"><img src="/dldimg/2dfbc937147931860215b03351817ad8_image1.jpg" width="100" height="100" border="0"></a>
		</div>
	</div>
</div>
</td>
</tr>
<tr>
<td>
<div class='resultItemWrapper'>
	<div class="resultImg">
    	<div align="center"><a href="/details.php?id=19735"><img src="/dldimg/9d43205d93bc6dc27133a467de1dc973_image1.jpg" width="100" height="100" border="0"></a>
		</div>
	</div>
</div>
</td>
<td><div class='resultItemWrapper'>
	<div class="resultImg">
    	<div align="center"><a href="/details.php?id=19342"><img src="/dldimg/a61d3c31b3b299195be97c27226b82ab_image1.gif" width="100" height="100" border="0"></a>
        </div>
    </div>
</div>
</td>
</table>
</div>

Open in new window

sphider3.png
I was able to get this to work by changing $tmp_cnt = 1.

Thanks!