Just PM here and Ill give you my MSN
A PHP if statement question
Moderator: General Moderators
A PHP if statement question
First of all I have only been playing with PHP for a few months now. I was wondering if it is possible to put a link in an Then section of the If statement....Also I have one page that I am trying to fix. There is too much code to put here. If anyoen has the experence please help
Thanks so much...
Just PM here and Ill give you my MSN
Just PM here and Ill give you my MSN
- hannnndy
- Forum Contributor
- Posts: 131
- Joined: Sat Jan 12, 2008 2:09 am
- Location: Iran>Tehran
- Contact:
Re: A PHP if statement question
1. using echo
Code: Select all
<?php
if($statement)
echo('<a href='url'>your text here</a>');
else
echo('<a href='url'>your sec text here</a>');
?>Code: Select all
<?php
if($statement)
{
?>
<a href='url'>your text here</a>
<?php
}
else
{
?>
<a href='url'>your sec text here</a>
<?php
}
?>
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: A PHP if statement question
I just have to ask, what have you tried so far? This is a fairly elementary practice (echoing data to the screen). Did you try this at all?
Re: A PHP if statement question
Everah | Please use the [code] or [code=php] tag when posting code in the forums.
i did, the problem is that I cant get it to display correctly without erroring out. Here is what I have.
But seeing from above I can see why is messed up. I have a game that we are working on and there are properties on the game. I want to have it to where if there is no owner, I want then to be able to "purchase" it, but im not sure.
Everah | Please use the [code] or [code=php] tag when posting code in the forums.
i did, the problem is that I cant get it to display correctly without erroring out. Here is what I have.
Code: Select all
if($owner == ""){ echo "<p class='warning'>This has no owner click <a href="?action=takeover">here</a> to take it over</p>";} else { echo " This is already owned";} Everah | Please use the [code] or [code=php] tag when posting code in the forums.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: A PHP if statement question
You need to read up on handling strings in PHP. It will teach you how to properly escape quotes in quoted strings.
Re: A PHP if statement question
Ok ill check it out.
Like I said im new to PHP, but am trying to learn what it is all about.
Like I said im new to PHP, but am trying to learn what it is all about.
Re: A PHP if statement question
I dunno if this will work, but do you think that I would be able to set it up to where if no owner then it displays a link that redirects to a new page, and then the new page would run the script for them?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: A PHP if statement question
Yes, you can do just about anything you want as long as you use the correct logic and syntax.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: A PHP if statement question
Doesn't mean anything. Errors are there to tell you what's wrong.Tharoah wrote:Erroring out
Strings don't read minds. I strongly suggest downloading SciTE or some similar program for coding. If you are going to have a string that contains "s, then either surround the string with 's instead of "s, or escape all "s with the \ character. It works the other way around, too.
Code: Select all
if ($owner==null){
echo "<p class=\"warning\">This has no owner click <a href=\"?action=takeover\">here</a> to take it over</p>";
}else{
echo " This is already owned";
}
Re: A PHP if statement question
Gotcha,
I did it that way and it seems to work now. I also found out that the DB didn't have enough tables to set the post correctly so thats what was going on with it. I have been reading the manual on the PHP site and I saw that on the 's. The story behind it is that I bought these couple of scripts because i did not know how to add casino like games to my site. The new one that got got has it set up that if you own a casino, then someone is supposed to be able to offer you money to buy it. I see the $ offer in there, but I still think it is jacked up. I'm not going to mess with it until I can either become more efficient at PHP and MySql or have someone help me.
I did it that way and it seems to work now. I also found out that the DB didn't have enough tables to set the post correctly so thats what was going on with it. I have been reading the manual on the PHP site and I saw that on the 's. The story behind it is that I bought these couple of scripts because i did not know how to add casino like games to my site. The new one that got got has it set up that if you own a casino, then someone is supposed to be able to offer you money to buy it. I see the $ offer in there, but I still think it is jacked up. I'm not going to mess with it until I can either become more efficient at PHP and MySql or have someone help me.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: A PHP if statement question
We are here to help. Don't give up.
Re: A PHP if statement question
thanks so much for all of your help. I am starting to learn that its actually worse to buy framework scripts then to write from scratch.
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: A PHP if statement question
Yes, I agree, it's the developer who determine which framework to use based on the requirement of a project, not the other way around.Tharoah wrote:thanks so much for all of your help. I am starting to learn that its actually worse to buy framework scripts then to write from scratch.