Hi, I'm developing a web app, but I think that maybe I'm not doing it the right way. See, for each page I take the GET variables from url, for instance:

www.webapp.com/?mode=register

That way, the index gets the variable and displays the right page, in this case, the registration page. But I do it this way:

<?php 
include "page/header.php";
if($_GET['mode']==='register'){
  //code for registration
  //this next file contains the HTML for the registration page.
  include "mod/register.php";
}elseif($_GET['mode']==='login'){
  //code for login
  include "mod/login.php";
}else{
 include "mod/404.php";
}
?>
include "page/footer.php";

Is that a good way of handling different pages from a single index.php? or is there a better way? because, to be honest, it's kinda difficult to develop this way. Especially when you create a header.php and a footer.php, where the header file contains the css link.

I see nothing wrong with having the index page handled this way, but I would not have every page in the site try to decide what page to display off of get variables.

OK, and yes, some pages are not accessible through GET variables. The one that processes new registrations, logins, new posts for instance are accessible only through a form with POST variables (or with a direct link that the user might not be even aware of) and with session validators to avoid forgery.

But there's another question.

Is it OK to do something like this?

<table>
<tr><th>Name</th><th>Email</th></tr>
<?php
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){?>
<tr><td><?php echo $row['name'];?></td><td><?php echo $row['email'];?></td></tr>
<?php }?>
</table>

I realize it gets difficult to maintain in the future, but for know that's how I'm handling my code. What do you think?

certainly, it is ok to do that, and yes, it is more difficult to maintain later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.