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
TLN_CANADAAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Marco GasiConnect With a Mentor FreelancerCommented:
Well, first I would try to change the function: use this instead

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

Open in new window


If this way still doesn't work, change also the link code this way:

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

Open in new window


It's less concise and elegant but this could be a small price to solve a problem :-)
0
 
gr8gonzoConsultantCommented:
<?php

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

...onClick='<?php echo ((trim($row['question'])== '') ? 'window.open(...)' : ''); ?>
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
TLN_CANADAAuthor Commented:
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?
0
 
gr8gonzoConsultantCommented:
I'm not sure what you're asking. I provided the code for you...
0
 
TLN_CANADAAuthor Commented:
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
0
 
gr8gonzoConsultantCommented:
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(...)' : ''); ?>'
0
 
Marco GasiFreelancerCommented:
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

0
 
Marco GasiFreelancerCommented:
Sorry, please ignore my comment...
0
 
TLN_CANADAAuthor Commented:
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

0
 
Marco GasiFreelancerCommented:
Well, to open two popups use the code in my comment ID: 38821596
0
 
TLN_CANADAAuthor Commented:
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

0
 
Marco GasiFreelancerCommented:
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

0
 
TLN_CANADAAuthor Commented:
Hey Marcus, unfortunately this way does not open anything at all when I click on this.
0
 
TLN_CANADAAuthor Commented:
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 :)
0
 
Marco GasiFreelancerCommented:
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.
0
 
TLN_CANADAAuthor Commented:
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.
0
 
Marco GasiFreelancerCommented:
we'll meet at the Cron Corner ;-)
0
 
TLN_CANADAAuthor Commented:
hahaha, yes :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.