A flat file search that just doesn't work... (help needed)
Posted: Thu Jun 01, 2006 8:00 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I've written this script, which should make a search through a flat file, find there those image files which are listed with the searched word and then show the files on a web page. My problem is, this script shows only the text "No photos. Sorry." - no matter if theres image files and data in the right directory and the flat file or not. I've tried for hours (and this is coming into my dreams too ) to figure out, why the script doesn't work properly. The problem must be actually very little, I just can't see it. If somebody here could help me with this, I would appreciate it a lot!Code: Select all
<?php
$file="directory/file.txt";
include("words.inc");
$word=$something_from_that_file_above;
// Search row by row, in temp1 is the wanted word, $temp[0] is the image file and $temp[2] is the text for it.
for($r=0;$r<sizeof($file);$r++) {
$temp = explode("|",$file[$r]);
$row[$r]="$temp[0]|$temp[1]|$temp[2]|";
$this = strchr($temp[1], $word);
if($this) {
$list[$a] = $row[$r];
$a++;
}}
// And what we'll get after that? We'll see the images we wanted? Or not?
if(sizeof($list) == 0) {
echo "<td>No photos. Sorry.</td>"; }
else {
for($b=0;$b<sizeof($list);$b++) {
$temp = explode("|", $list[$b]);
// A link to the bigger picture.
$link = "view.php";
$numbers=array(2,4,6,8);
// View small photos with short descriptions.
$descript = strchr($temp[2], 10);
echo "<td><a href=\"",$link,"\">",$descript,"<br><img src=\"",$temp[0],"\" width=\"250\" height=\"190\"></a></td>";
// Makes a new line of pictures when $b can be found from the array "$numbers".
if(in_array($b, $numbers)) {
echo "</tr><tr>"; }
}}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]