Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in displaying just one line of a file determined by url param

Status
Not open for further replies.

atom267

Technical User
Mar 3, 2004
5
0
0
GB
Hi i've spent quite a lot of time on this problemn and seriously, i dont see what's wrong with my code. I've got a file in which each line contains different information separated by |. One of this information is calles let's say 'Name'. I pass the parameter Name by Url to my script. Then i assign to the variable $var this value. After i want to display just the information concerning the name, which is the fist information in each line.
@data is an array containing the content of the file.
This is what i do.


foreach $i (@data) {
chomp($i);
($name,$description,$price,$supplier,$stock) = split(/\|/,$i);
if ($var == $name)
{
print<<EndHTML;
body>
<table width="75%" border="1" align="center">
<tr>
<td width="20%" height="23"><div align="center">$name</div></td>
<td width="20%" height="23"><div align="center">$description</div></td>
<td width="20%" height="23"><div align="center">$price</div></td>
<td width="20%" height="23"><div align="center">$supplier</div></td>
<td width="20%" height="23"><div align="center">$stock</div></td>
</tr>
</table>
</body>
EndHTML
}
}

The result to that is the displaying of all the lines of the file, including those whose $name is different than $var !!
I really dont understand. What do i need to do? It's just a simple condition.
Thanks if any of you has a suggestion
 
You're using "==", which is the numeric comparison operator.
I think you want to use "eq", the string comparison operator, i.e., "if ($var eq $name)"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top