Adding if to this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

Adding if to this code

Post by kevrelland »

i have tried again with my code see my previous post hereviewtopic.php?f=1&t=119814 Got in a bit of a mess, so i sat down and worked through it again and hopefully looks better.
But I want to add into here an if and an else statement so that if $_GET{"image_id_1] is not null or set from the url this line does not show "$image1 = "image_id_1=" . $_GET["image_id_1"] . "&";"
I've tried this:

Code: Select all

$image1 = if ($_GET["image_id_1"]!="") echo "image_id_1=" . $_GET["image_id_1"] . "&" };
but it returns a :- Parse error: syntax error, unexpected T_IF
Here is the full code

Code: Select all

<?php 
			$returnurl = $_GET["url"] . ".php?";
			$image1 = "image_id_1=" . $_GET["image_id_1"] . "&";
			$image2 = "image_id_2=" . $_GET["image_id_2"] . "&";
			$image3 = "image_id_3=" . $_GET["image_id_3"] . "&";
			$position = $_GET['image_position'];
			$newimage = "image_id" . $position ."=" .stripslashes($row['imagename']);
			$prod_id = "id=" . $_GET["id"];
			$position = $_GET['image_position'];
			echo $returnurl . $prod_id . $image1 . $image2  . $image3 . $newimage ;
		?>
hopefully it's something simple
Cheers
Kevin
User avatar
axcrow
Forum Newbie
Posts: 9
Joined: Mon Aug 09, 2010 12:22 pm

Re: Adding if to this code

Post by axcrow »

Hello,
this is what you should use

Code: Select all

$image1 = ($_GET["image_id_1"]!="") ? "image_id_1=" . $_GET["image_id_1"] . "&"  : '';
Post Reply