?
Solved

Skipping a certain div with a not null statement

Posted on 2016-10-08
11
Medium Priority
?
47 Views
Last Modified: 2016-10-10
<div id="mainarea">
	<div id="sidebar">
		<div id="sidebarnav">
		<a class="active" id="home_btn" href="#">Enter Posting Date</a>
		<!-- <a href="#" id="view_all">View CPT Price</a> -->

		</div>
		</div>

	<div id="contentarea">

		<h2>Hello, Please let me know which date you are looking:</h2>
        <div><label style="font-size: 14pt; font-family: Verdana;">Posting Date: </label></div><br />
		<input type="text" id="date" value= "<?php echo $_GET['id']?>" class="css-input" placeholder="Posting Date..." readonly="readonly" /><br /><br />
		
        <input type="button" id="validate" value="Let's get to work!" class="btn" /> 
        <input type="button" id="clear" value="Wanna go Again?" class="btn" />
	</div>
	

		<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                      Code
                    </td>
                    <td>
                        # Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>

	
	</div>

Open in new window


I have the code above I want an if statement that if $_GET['id'] is not null for it to go to <div id="contentarea2" style="display: none;"> directly with a loader showing and skip the first div, and if not, for it to go through both of them?
0
Comment
Question by:Jasmine Ikhreishi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41835123
Do you mean like this.
if (!empty($_GET['id'])) {
 // Do the bit that requires the ID
}
// Rest of code here

Open in new window

0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41835125
Yeah but I tried it by doing this:
	</div>
	<?php 
if($_GET['id'] != NULL){

?>
	<div class="loader"></div>
	
		<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                         Code
                    </td>
                    <td>
                        # Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>
<?php } else{

}?>
	
	<div id="mainarea">
	<div id="sidebar">
		<div id="sidebarnav">
		<a class="active" id="home_btn" href="#">Enter Posting Date </a>
		<!-- <a href="#" id="view_all">View CPT Price</a> -->

		</div>
		</div>

	<div id="contentarea">

		<h2>Hello, Please let me know which date you are looking for :</h2>
        <div><label style="font-size: 14pt; font-family: Verdana;">Posting Date: </label></div><br />
		<input type="text" id="date" value= "<?php echo $_GET['id']?>" class="css-input" placeholder="Posting Date..." readonly="readonly" /><br /><br />
		
        <input type="button" id="validate" value="Let's get to work!" class="btn" /> 
        <input type="button" id="clear" value="Wanna go Again? " class="btn" />
	</div>
	

		<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                         Code
                    </td>
                    <td>
                        #  Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>

Open in new window


but didnt work
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41835146
That won't work - if id is not sent in the URL then it will not be defined in the $_GET array and any attempt to access $_GET['id'] will result in an error.

That is why we have empty() and isset() either can be used in this case.
0
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.

 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41835150
so instead of doing != Null I just do if not !empty?
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41835152
Yup
0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41835154
I did it like this:
	<?php 
if (!empty($_GET['id'])){

?>
	<div class="loader"></div>
	<div id="mainarea">
	<div id="sidebar">
		<div id="sidebarnav">
		<a class="active" id="home_btn" href="#">Enter Posting Date </a>
		<!-- <a href="#" id="view_all">View CPT Price</a> -->

		</div>
		</div>
	<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                        Code
                    </td>
                    <td>
                        # Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>

	
	</div>
	
	
	
<?php }
else{?>
	
	<div id="mainarea">
	<div id="sidebar">
		<div id="sidebarnav">
		<a class="active" id="home_btn" href="#">Enter Posting Date </a>
		<!-- <a href="#" id="view_all">View CPT Price</a> -->

		</div>
		</div>

	<div id="contentarea">

		<h2>Hello, Please let me know which date you are looking for :</h2>
        <div><label style="font-size: 14pt; font-family: Verdana;">Posting Date: </label></div><br />
		<input type="text" id="date" value= "<?php echo $_GET['id']?>" class="css-input" placeholder="Posting Date..." readonly="readonly" /><br /><br />
		
        <input type="button" id="validate" value="Let's get to work!" class="btn" /> 
        <input type="button" id="clear" value="Wanna go Again? OK!" class="btn" />
	</div>
	

		<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                        Code
                    </td>
                    <td>
                        # Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>

	
	</div>
	<?php }?>

Open in new window


The if statement shows nothing but the else works
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41835163
Just understanding your requirement. I understood you wanted
if (!empty($_GET['id')) {
   // show this
}
// Show this irrespective of whether there is an id

Open in new window

In which case no else is required.
What do you want to do - do you only want to show the first part if there is an ID
And ONLY the second part if there is one?
0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41835165
I want if there is an ID to show just the second part and if there Isnt to show both parts
0
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41835249
then remove the else part - right now you are doing an either or
If there is an ID show the first
If not then show the second.

I want if there is an ID to show just the second part
Your logic is back to front currently you have
if (!empty(...))
Which is saying if there IS an id show the FIRST part
If there is not an ID show the second part.

This is probably what you want.
<?php 
// IF NO id SHOW THE FIRST PART
if (empty($_GET['id'])) :
?>
	<div class="loader"></div>
	<div id="mainarea">
	<div id="sidebar">
		<div id="sidebarnav">
		<a class="active" id="home_btn" href="#">Enter Posting Date </a>
		<!-- <a href="#" id="view_all">View CPT Price</a> -->

		</div>
		</div>
	<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                        Code
                    </td>
                    <td>
                        # Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>

	
	</div>
	
	
	
<?php 
  endif;
// SHOW SECOND PART REGARDLESS
?>
	
	<div id="mainarea">
	<div id="sidebar">
		<div id="sidebarnav">
		<a class="active" id="home_btn" href="#">Enter Posting Date </a>
		<!-- <a href="#" id="view_all">View CPT Price</a> -->

		</div>
		</div>

	<div id="contentarea">

		<h2>Hello, Please let me know which date you are looking for :</h2>
        <div><label style="font-size: 14pt; font-family: Verdana;">Posting Date: </label></div><br />
		<input type="text" id="date" value= "<?php echo $_GET['id']?>" class="css-input" placeholder="Posting Date..." readonly="readonly" /><br /><br />
		
        <input type="button" id="validate" value="Let's get to work!" class="btn" /> 
        <input type="button" id="clear" value="Wanna go Again? OK!" class="btn" />
	</div>
	

		<div id="contentarea2" style="display: none;">
		
        <h2>Results:</h2>
        <div class="view_alerts">
            <table>
                <tr>
                    <td>
                        Code
                    </td>
                    <td>
                        # Posted
                    </td>
                    
                </tr>
                <tbody id="view_alerts_tbody">

                </tbody>
            </table>
        </div>
	</div>

	
	</div>

Open in new window

NB: You will note I changed your if statement from using {} to : endif.
PHP supports two statement block delimiters
if (condition) {
}
else {
}

Open in new window

And
if (condition) :
else :
endif;

Open in new window

I prefer to use the second when including logiic mixed with HTML - it makes the closing of the block easier to see.
0
 
LVL 1

Author Closing Comment

by:Jasmine Ikhreishi
ID: 41836705
Thanks this helped me loads!
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41836759
You are most welcome.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

800 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