Solved

Skipping a certain div with a not null statement

Posted on 2016-10-08
11
33 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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
so instead of doing != Null I just do if not !empty?
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
Yup
0
Easy Project Management (No User Manual Required)

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 1

Author Comment

by:Jasmine Ikhreishi
Comment Utility
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 51

Expert Comment

by:Julian Hansen
Comment Utility
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
Comment Utility
I want if there is an ID to show just the second part and if there Isnt to show both parts
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
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
Comment Utility
Thanks this helped me loads!
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
You are most welcome.
0

Featured Post

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

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

762 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

9 Experts available now in Live!

Get 1:1 Help Now