I have a page that has html and javascript code for all the layout and graphics. In addition to that, I also have the PHP code that load some data from MySQL database. Now the question is, if the query to load data from the database failed to match any, I want to stop executing the whole PHP block of code but still executing the html and javascript code that comes after the PHP block of code. I'm currently use the exit; to stop the executing of the PHP block of code; however, I found that my menu, which I use javascript, does not show up at the bottom. Instead it has been pushed to show half of the menu bar on the top of the page. Here's the page, http://www.uwstout.edu/alumni/temp/pssW ... ieve.shtml, I'm talking about. If click on the button and the page failed to match anything, you'll see the problem I am facing.
Any suggestion is much appreciated.
ljCharlie
How to exit out of PHP block of code?
Moderator: General Moderators
Many thanks for your help and suggestion. The problem is I also check if the user fill in all the textboxes, I could have use javascript to check within the .shtml page, but I didn't. Anyway, I check these textboxes in the .php page and if they failed, I want to stop executing the php code as well. I'm using the IF statement, the problem is what's the code to not run anymore php code if the requirement has not been met?
ljCharlie
ljCharlie
Basically like this:
Code: Select all
<?php
if ( requirementsAreMet() ) {
// run code
}
?>
HTML code goes hereI can see your suggestion may stop the php code; however, in my situation I think that it will be hard to incoporate to have it working. With your suggestion, it forces me to have many multiple subset of IF statements. If I don't have subset of IF statement and instead having multiple PHP block of code, then the problem is even if the first block of PHP code stop executing, it's going to come down to the second, third, etc block of code and execute.
ljCharlie
ljCharlie
No it doesn't. If your setup requires you to have multiple layers of IF statements, than that's your setup, not my solution. Besides, all you are saying is that if the query doesn't return a result, you don't want to run any more code. That's a single condition.With your suggestion, it forces me to have many multiple subset of IF statements.
Maybe you should provide some code so we can work with it, and possibly help you improve the structure. Otherwise, all I can do is give you an answer based on my assumptions. And while I've been coding PHP for some time (and I imagine I am somewhat skilled in that area), I have yet to master the ability to view people's hidden code.