tj99ay Posted August 29, 2007 Share Posted August 29, 2007 Hi All, I only dabble in PHP, thus my urgent need for help. I currently have this which works fine: <? $readfile = "UnitPrice_2.txt"; if (file_exists($readfile)) { $readfile = file("UnitPrice_2.txt"); $readfile_sort = array_reverse($readfile); for ($k=0; $k<=count($readfile_sort)-2; $k++) { $fields = split("\t",$readfile_sort[$k]); print("<tr onMouseOver=this.className='rowHighlight'; onMouseOut=this.className='rowEven';><td class=plain> $fields[0]</td> <td align=Center class=plain>$fields[1]</td> <td class=plain align=Center>$fields[2]</td> <td class=plain align=Center>$fields[3]</td></tr>"); } } else { print ("<p><span class=subheading>Sorry data temporarily unavailable, please try again later.</span></p>"); } ?> but I want to change the code to match two fields - 1 from each external tab delimited text file. If $fields[0] and $field2[0] match (it's actualy checking for a matching date) display something in $showtext. I know what I want to do with the code, but I don't have enough knowledge to actually write it properly. This is what I have done thus far which does not work: <? $readfile = "UnitPrice_2.txt"; $readfile2 = "ExDist_2.txt"; if (file_exists($readfile) || file_exists($readfile2)) { $readfile = file("UnitPrice_2.txt"); $readfile2 = file("ExDist_2.txt"); $readfile_sort = array_reverse($readfile); $readfile_sort2 = array_reverse($readfile2); for ($k=0; $k2=0; $k<=count($readfile_sort)-2; $k2<=count($readfile_sort2)-2; $k++; $k2++) { $fields = split("\t",$readfile_sort[$k]); $fields2 = split("\t",$readfile_sort2[$k2]); if ($fields[0] == $fields2[0]) { $showtext = "Ex-Distribution"; } else { $showfields = " "; } print("<tr onMouseOver=this.className='rowHighlight'; onMouseOut=this.className='rowEven';><td class=plain> $fields[0]</td> <td align=Center class=plain>$fields[1]</td> <td class=plain align=Center>$fields[2]</td><td class=plain align=Center><strong>$showtext</strong></td></tr>"); } else { print ("<p><span class=subheading>Sorry data temporarily unavailable, please try again later.</span></p>"); } ?> Any urgent guidance would be appreciated. Many thanks tj99ay Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 29, 2007 Share Posted August 29, 2007 Well, your for loop doesn't make sense. You can't have two conditions within your for loop. I assume that by "does not work" you mean you end up with a blank page? Or do you actually get the error message? Either way, it would be helpful to be a bit more descriptive of the problem. Anyways, i would suggest constructing your for loop as something like: <?php for($k=0;$k<=count($readfile_sort)-2;$k++{ $k2 = $k+1; //rest of your code here } ?> That should be ok if the only matches you want to find are those where the 1st tab delimited value in file 1 is the same as the 3rd tab delimited value in file 2 and are on the same line within their respective files. If thats not what you're after, you'll need to explain a bit more fully with what you are trying to achieve. Quote Link to comment Share on other sites More sharing options...
tj99ay Posted August 30, 2007 Author Share Posted August 30, 2007 Hi, Thanks for your reply. Yep my loop doesn't make sense, that's what I was asking for someone to help. Very bad explanation I agree. Good news though, I paid a PhpFreak user to get it done for me instead. Thanks anyway! Quote Link to comment Share on other sites More sharing options...
trq Posted August 30, 2007 Share Posted August 30, 2007 You can't have two conditions within your for loop. Actually you can. You can have as many as you like seperated by commas. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.