473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

PHP if statement within echo?

2
Hi everyone, i have a php script that echoes the following code from an if statement, what i need to do is make part of this [marked //This section] only show if ($cat=="fireplaces.php"). Does anybody have any suggestions as to how i could do this, can i put an IF statement within the ECHO? I hope i've explained myself well enough, i can clarify if necessary, i can also supply more of the code if necessary.

thanks
Andy



Expand|Select|Wrap|Line Numbers
  1. echo "
  2. <div id=hrule><hr></div>
  3. <div id=top>
  4. <br>
  5. $ItemName 
  6. </div>
  7. <div id=middle>
  8. <div id=details>
  9. <p>
  10. <b>Price:</b> &pound;$Price
  11. <p>
  12. <b>Delivery Cost:</b> &pound;$Shipping
  13. <br><br><br><br><br><br>
  14. <form action=####################### method=post>
  15. <input type=hidden name=itemname value='$ItemName'>
  16. <input type=hidden name=price value=$Price>
  17. <input type=hidden name=storeid value=#########>
  18. <input type=hidden name=quantity value=1>
  19. <input type=hidden name=shipping1 value=$Shipping>
  20. <input type=hidden name=displaycart value=no>
  21.  
  22. *~*~*~*~*~*~*~*~*~*~ //This section
  23. <input type=hidden name=X1itemname value='$ItemName Fireplace Installation'> 
  24. <input type=hidden name=X1price value=70.00>
  25. <input type=hidden name=X1storeid value=############>
  26. <input type=hidden name=X1quantity value=1>
  27. Optional Fireplace Installation: 
  28. <input type=checkbox name=X1include><br><br> 
  29. *~*~*~*~*~*~*~*~*~*~
  30.  
  31. <input type=image src='style/button.gif' alt='Add to Basket'>
  32. <p>
  33. </form>
  34. </div> 
  35. <div id=thumbnail><a href='pages/products/images/$ItemCode.jpg' rel='lightbox' title='$ItemName' onfocus='this.blur()'><img class=border src='pages/products/thumbnails/$ItemCode.jpg' border:'none'><br><img src='style/enlarge.jpg'></a></div> 
  36. </div>
  37.  
  38. <div id=bottom>
  39. <div id=description>$Description</div>
  40. </div>
  41.  
  42. ";
Oct 6 '07 #1
5 38036
pbmods
5,821 Expert 4TB
Heya, Andy. Welcome to TSDN!

The easiest thing to do is to terminate the string, run the conditional, and then echo the rest of the output:

Expand|Select|Wrap|Line Numbers
  1. echo <<<END
  2.     ...
  3. END;
  4.  
  5. if( $condition )
  6. {
  7.     echo <<<END
  8.     ....
  9. END;
  10. }
  11.  
  12. echo <<<END
  13.     ...
  14. END;
  15.  
Oct 7 '07 #2
Atli
5,058 Expert 4TB
Hi Andy. Welcome!

You could also try running the if statement before the echo:
Expand|Select|Wrap|Line Numbers
  1.  
  2. if($theSky == "blue") {
  3.   $msg = "The sky is blue!";
  4. }
  5. else {
  6.   $msg = "What?";
  7. }
  8.  
  9. echo "Some text: $msg End of text!";
  10.  
Oct 7 '07 #3
You can also user ternary operators:

Expand|Select|Wrap|Line Numbers
  1. echo "always say this " . ( ($test == "true") ? "Say this if that is true"   : "") . " Always say this at the end.";
  2.  
Oct 7 '07 #4
AnDyG
2
thanks for the replies everyone, i used Atli's solution as it seemed simplest to implement, though i'm sure all of your suggestions would have worked.
Problem now sorted

thanks
Andy
Oct 7 '07 #5
pbmods
5,821 Expert 4TB
Heya, Andy.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Oct 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John Morgan | last post by:
In a 'Top n' type statement I wish to be able to insert the n value from a parameter, within a stored precedure eg Having declared @pageSize as a parameter I want to run the following type of...
8
by: abbylee26 | last post by:
User enters account number if another account number is needed User clicks add account which creates another row When validating when they hit submit I want to check to make sure they tell us...
1
by: philipdm | last post by:
Ok, I have a data warehouse that I am pulling records from using Oracle SQL. I have a select statement that looks like the one below. Now what I need to do is where the astrics are **** create a...
30
by: Mark | last post by:
I am a complete novice with php scrip but I am wiling to learn. I am in need of some help, please. Can anyone sort this code out for me so that it works correctly and adjusts the price for the...
4
by: Birky | last post by:
Can someone help me enter a sort statement into the below SQL statement? For the life of me I can not get it to work and I have tried everything I can think of. I just need this stupid thing to sort...
6
by: BobRoyAce | last post by:
Let's say that I am performing a bunch of insert/update queries within a transaction that is created as follows: Dim cnn As New SqlClient.SqlConnection(My.Settings.GRPConnectionString)...
2
by: ianmcdonagh | last post by:
Hi folks, I'm looking to pick everyone's brains. I have a cursor, with over 200 columns in the select. I am using a case in one of the columns which I'm retrieving, and want to issue an...
5
by: tasteofchaos | last post by:
Hey guys. Unfortunately I can't break out of an echo to run the if statement I want to run because it's pulling data for a certain row. I'd like text truncated to a certain amount of characters...
12
by: omar999 | last post by:
im using classic asp and sql server. my if statement checks if there is a price within 5 places and then if any has a value shoud output 'I HAVE DATA' but it doesnt.. can anyone help? i dont get...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.