Link to home
Start Free TrialLog in
Avatar of TLN_CANADA
TLN_CANADAFlag for Afghanistan

asked on

PHP if statement

Hi everyone,

I have a page where I want to a second popup to be displayed if a particular variable is empty.

The variable is called $row['question'] and if it is empty I want it to open a second popup page called med4.php. There is already another popup opened from the same link that I want opened regardless of this (this part is already working). Here is the place i want this added to:

<div class="col_1 firstcolumn">
                    <a href="http://www.clear.com/mednowjan25.php?min=40&int=05" onClick="Popup2=window.open('http://www.clear.com/mednowjan25.php?min=40&int=05','Popup2','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=750,height=410'); return false;">Standard </br>(40 Minutes) </br> (5 minute intervals)</a>
                    </div>

Open in new window


Thanks for your help with this,

D
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

<?php

if(trim($row['question']) == '')
{
  echo "<script type='text/javascript'>window.open(.....);</script>";
}
?>
If you want to use it inline:

...onClick='<?php echo ((trim($row['question'])== '') ? 'window.open(...)' : ''); ?>
Avatar of TLN_CANADA

ASKER

Thank you gr8gonzo, how can I integrate this into my existing script though so that it will open this second popup if the variable is blank?
I'm not sure what you're asking. I provided the code for you...
Hi gr8gonzo,


You can see I have a list field above. Within it at the moment on click it opens a popup. I would like to add your code to this so that if the variable is empty, it opens a second popup at the same time and if the variable has a value, it only opens the 1 popup as I already have. I hope this makes sense and thank you for your help,

D
I understand what you want, but I've provided the code you are asking for in my second comment. Where you have your onClick in your existing code, just integrate the part from <?php to ?>

Existing:
onClick='window.open(...etc...)'

Modified:
onClick='window.open(...etc...); <?php echo ((trim($row['question'])== '') ? 'window.open(...)' : ''); ?>'
You can try this function:

<script type="text/javascript">
  function showPops(pop1, pop2) {
    self.open (pop1, 'pop1','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=750,height=410');
    self.open (pop2, 'pop2','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=750,height=410');
}  

Open in new window


Call it this way:

<div class="col_1 firstcolumn">
  <a href="#" onClick="showPops('http://www.clear.com/mednowjan25.php?min=40&amp;int=05', 'http://www.clear.com/mednowjan25.php?min=40&amp;int=05');">Standard </br>(40 Minutes) </br> (5 minute intervals)</a>
</div>

Open in new window

Sorry, please ignore my comment...
Thank you, I must be doing something wrong with it as this is what is displayed in the url as it only opens one popup:

http://www.clear.com/mednowjan25.php?min=40&int=05window.open(http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28009690.html#a38821588)

It opens the clear.com and not both.

Here is the code I have on the page:

                    <div class="col_1 firstcolumn">
                    <a href="http://www.clear.com/mednowjan25.php?min=40&int=05" onClick="Popup2=window.open('http://www.clear.com/mednowjan25.php?min=40&int=05<?php echo ((trim($row['question'])== '') ? 'window.open(http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28009690.html#a38821588)' : ''); ?>','Popup2','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=750,height=410'); return false;">Standard Dyad </br>(40 Minutes) </br> (5 minute intervals)</a>
                    </div>

Open in new window

Well, to open two popups use the code in my comment ID: 38821596
Thanks Marcus! You're code working perfectly for opening 2 popups. I am having trouble integrating the PHP if statement into it though. It's giving this error at the moment:

and here's what I have:

Parse error: syntax error, unexpected ')' in /home/clear555/public_html/dyadmenu.php on line 103

<div class="col_1 firstcolumn">
					<a href="#" onClick="showPops('http://www.clear.com/mednowjan25.php?min=40&amp;int=05', <?php echo ((trim($row['question'])== '') ? 'http://www.clear.com/mednowjan25.php?min=40&amp;int=05') ?>'');">Standard </br>(40 Minutes) </br> (5 minute intervals)</a>
					</div>

Open in new window

You can try this:

<div class="col_1 firstcolumn">
<a href="#" onClick="showPops('http://www.clear.com/mednowjan25.php?min=40&amp;int=05', 
  <?php echo trim($row['question'])== '' ? 'http://www.clear.com/mednowjan25.php?min=40&amp;int=05' : '' ?>);">
  Standard </br>(40 Minutes) </br> (5 minute intervals)</a>
</div>

Open in new window

Hey Marcus, unfortunately this way does not open anything at all when I click on this.
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey Marcus, the second solution works, thank you!

 I have a question about this though, this page I have these functions on is very big and I will need to do this with about 6 others links so I'm wondering will this be a problem in any way on the page load repeating the if statements like this? It probably isn't but I wanted to check as this page has so much on it already that I don't want to fill it up more if it slows down things :)
I really don't know answer to this: I don't know performances issues since I'm not a professionals and I have only a couple of my sites with a few number of visitors... :-( I think this depends anyway on several thing: the connection speed, the bandwidth you have, the amount of simoultaneous visitors and so on. I'm very sorry to not be able to help you in this.
No worries at all Marcus! I will use this for now and look into changing it around at a later stage if there are any issues with the page loading speeds.

Thanks for your great help once again.
we'll meet at the Cron Corner ;-)
hahaha, yes :)