Frank_Rizzo

msg:4431676 | 10:36 am on Mar 21, 2012 (gmt 0) |
You just have to be aware of mixing the single and double quotes - they have to be balanced and in some cases escaped. Best way to learn this is to split your desired html output into different lines and then see which line triggers the error.
if($filter_selected){ echo '<div id="remove_all">'; echo '<a href="$sess->url($_SERVER['PHP_SELF'].'?page=shop.browse&category_id='.$category_id )">'; echo 'Remove</a></div>'; }
run that and you will see the error line being the one with $sess. If you still can't spot the error split it up further
echo '<a href="$sess->url($_SERVER['PHP_SELF']'; echo '?page=shop.browse&category_id='; echo $category_id; echo ')">';
You should now see which line(s) are not matching single and double quotes. Editing one line like this is much easier than trying to edit a whole line like this echo '<div id="remove_all"><a href="$sess->url($_SERVER['PHP_SELF'].'?page=shop.browse&category_id='.$category_id )">Remove</a></div>'; . . . If you still can not spot it the problem is with the single quotes around PHP_SELF. They need to be escaped [\'PHP_SELF\']
|
rocknbil

msg:4431748 | 3:55 pm on Mar 21, 2012 (gmt 0) |
Another less graceful and not so pretty approach, you can surround other blocks and php calls with php . . . like <?php if ($filter_selected) { ?> <p>This will only display if filter selected.</p> <?php } // end the IF ?> This allows you to only echo where you need it, and can contain other nested php calls. so you can do <?php if ($filter_selected) { ?> <div id="remove_all"><a href="<?php echo $sess->url($_SERVER['PHP_SELF'].'?page=shop.browse&category_id='.$category_id);?>">Remove</a></div> <?php } // end the IF ?> IMO this makes for some sloppy programming that's hard to debug but PHP lends itself to it very easily and works in a pinch. Note the big difference is you're not echoing static HTML, just the stuff from PHP - be sure to note the ending ; after the parentheses: <?php echo $sess->url($_SERVER['PHP_SELF'].'?page=shop.browse&category_id='.$category_id);?> <--- right there An aside, it seems like calling a class and using PHP_SELF just for the script's name is really a long way to go about what you're doing. PHP_SELF has potential security issues anyway. I'd just define the script name somewhere and do $thisscript = 'myscript.php'; <?php echo "/$thisscript?page=shop.browse&category_id=$category_id";?> By using double quotes it allows the scalar variables to interpolate and is much simpler to debug.
|
geompak

msg:4431765 | 4:52 pm on Mar 21, 2012 (gmt 0) |
I must thank you both. Frank Rizzo thank you for the guide on how find errors. And rocknbil indeed a <p> can do the job. and i ll change the PHP_SELF with the domain like this <?php echo 'http://www.example.com?page=shop.browse&category_id='.$category_id);?>
|
|