Solved

Skipping a certain div with a not null statement

Posted on 2016-10-08
11
40 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
  • 6
  • 5
11 Comments
 
LVL 52

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 52

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

Author Comment

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

Expert Comment

by:Julian Hansen
ID: 41835152
Yup
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 52

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 52

Accepted Solution

by:
Julian Hansen earned 500 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 52

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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 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…

910 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

16 Experts available now in Live!

Get 1:1 Help Now