Solved

Skipping a certain div with a not null statement

Posted on 2016-10-08
11
42 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 55

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 55

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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

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

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 55

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 55

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 55

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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.
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.

809 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