Page 1 of 1
A PHP if statement question
Posted: Sat Jan 12, 2008 2:44 am
by Tharoah
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
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 3:16 am
by hannnndy

there are two ways :
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>');
?>
2. using pure html in code
Code: Select all
<?php
if($statement)
{
?>
<a href='url'>your text here</a>
<?php
}
else
{
?>
<a href='url'>your sec text here</a>
<?php
}
?>
?>
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 10:57 am
by RobertGonzalez
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
Posted: Sat Jan 12, 2008 2:35 pm
by Tharoah
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";}
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.
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 3:02 pm
by RobertGonzalez
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
Posted: Sat Jan 12, 2008 4:04 pm
by Tharoah
Ok ill check it out.
Like I said im new to PHP, but am trying to learn what it is all about.
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 4:05 pm
by Tharoah
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?
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 4:58 pm
by RobertGonzalez
Yes, you can do just about anything you want as long as you use the correct logic and syntax.
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 6:41 pm
by Jonah Bron
Tharoah wrote:Erroring out
Doesn't mean anything. Errors are there to tell you what's wrong.
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
Posted: Sat Jan 12, 2008 7:32 pm
by Tharoah
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.
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 8:09 pm
by RobertGonzalez
We are here to help. Don't give up.
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 8:18 pm
by Tharoah
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.
Re: A PHP if statement question
Posted: Sat Jan 12, 2008 11:56 pm
by jimthunderbird
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.
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.