Solved

PHP if statement

Posted on 2013-01-25
19
422 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 34

Expert Comment

by:gr8gonzo
ID: 38821552
<?php

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

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
 
LVL 34

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 34

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 30

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 30

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

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 30

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 30

Accepted Solution

by:
Marco Gasi earned 500 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 30

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 30

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now