Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP if statement

Posted on 2013-01-25
19
Medium Priority
?
437 Views
Last Modified: 2013-01-26
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
0
Comment
Question by:TLN_CANADA
  • 8
  • 7
  • 4
19 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 38821552
<?php

if(trim($row['question']) == '')
{
  echo "<script type='text/javascript'>window.open(.....);</script>";
}
?>
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 38821554
If you want to use it inline:

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

Author Comment

by:TLN_CANADA
ID: 38821556
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:gr8gonzo
ID: 38821559
I'm not sure what you're asking. I provided the code for you...
0
 

Author Comment

by:TLN_CANADA
ID: 38821576
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
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 38821588
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38821596
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38821599
Sorry, please ignore my comment...
0
 

Author Comment

by:TLN_CANADA
ID: 38821623
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38821673
Well, to open two popups use the code in my comment ID: 38821596
0
 

Author Comment

by:TLN_CANADA
ID: 38821687
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38821692
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
 

Author Comment

by:TLN_CANADA
ID: 38821699
Hey Marcus, unfortunately this way does not open anything at all when I click on this.
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 38821716
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
 

Author Comment

by:TLN_CANADA
ID: 38821734
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38821743
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
 

Author Comment

by:TLN_CANADA
ID: 38821751
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 38821757
we'll meet at the Cron Corner ;-)
0
 

Author Comment

by:TLN_CANADA
ID: 38821765
hahaha, yes :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question