Jump to content

A simple display logical error


arunkar

Recommended Posts

Hi experts,

 

Im doing a simple logical statement, I'm pulling out the data from the database and if the count result from DB is 0 then I do not want to display a link. Else if there is a number I want to display a link. I did a very simple if statement but it throws a error below:

 

Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in /chroot/home/dashboard/index.php on line 81

 

 

Code:

<?php foreach($rowWC as $fieldName => $field) // line 81
							{ 
							 if($field >0) 
								{echo "<a href='javascript:popUp('details.php?MR=WC')'>" $field "</a>"; 
								}
							 else 
							 	{echo "0";}
							}?>

 

could advice please?

 

cheers

Arun

Link to comment
https://forums.phpfreaks.com/topic/98826-a-simple-display-logical-error/
Share on other sites

Parse error is a code syntax error not logic :P.

 

unexpected T_VARIABLE means it saw a $ symbol where it shouldn't be, try this:

 

<?php foreach($rowWC as $field) // line 81
							{ 
							 if($field >0) 
								{echo "<a href='javascript:popUp('details.php?MR=WC')'>" $field "</a>"; 
								}
							 else 
							 	{echo "0";}
							}?>

Thanks uniflare,

 

I did the changes:

 

I put this code:

 

<?php foreach($rowWC as $field) // line 81
							{ 
							 if($field >0) 
								{echo "<a href='javascript:popUp('details.php?MR=WC')'>" $field "</a>";  //line 84
								}
							 else 
							 	{echo "0";}
							}?>

 

but it showed mew an error in line 84.

 

what could have gorn?

Ah dint notice that 1, you need concatenation (period)... ie;

 

<?php foreach($rowWC as $field) // line 81
							{ 
							 if($field >0) 
								{echo "<a href='javascript:popUp('details.php?MR=WC')'>" . $field . "</a>";  //line 84
								}
							 else 
							 	{echo "0";}
							}?>

 

Also try structuring your code a little differently:

 

<?php 
foreach($rowWC as $field){ // line 81
   if($field >0){
      echo "<a href='javascript:popUp('details.php?MR=WC')'>" . $field . "</a>";  //line 84
   }else{
      echo "0";
   }
}?>

 

hope this helps,

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.