Solved

Skipping a certain div with a not null statement

Posted on 2016-10-08
11
41 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 54

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 54

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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 1

Author Comment

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

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 54

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 54

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 54

Expert Comment

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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP: Insert Data into MySQL 5 40
Can't find PHP files on account that has WordPress 3 26
does post require a form or curl to be post 4 31
Decrypt string by php 7 31
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 …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

770 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