Jump to content

Recommended Posts

Hey here is my code im trying to redirect  the index.php to index.php?id=1

the way i have done it doesn't look really good is there a better way to do it please?

 

im trying to redirect to id=1 because otherwise i wont be able to echo out anything...

 

id 1 is default category so is there a way to tell it if  $id is empty echo from id 1?

 

<?php   

        $id = $_GET['id']; 
		if($id == ''){
			echo "<meta http-equiv=Refresh content=0;url=index.php?id=1>";

		}	
        $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect);
        while($row = mysql_fetch_assoc($result))
             {
        echo $row['anything1']; 
        echo $row['anything2']; 
} 
?>

Don't bother actually redirecting, just set a default.

 

You really need to check your query results before using them too.

 

if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
} else {
  $id = 1;
} 

if ($result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      echo $row['anything1']; 
      echo $row['anything2']; 
    }
  }
}

I don't know that this is exactly what you are asking but if it is not please be more specific:

 

<?php   

        $id = $_GET['id']; 
            if($id == '1'){
                header("location: ./index.php?id=1");
            }
        $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect);
        while($row = mysql_fetch_assoc($result)){
            echo $row['anything1']; 
            echo $row['anything2']; 
        } 
?>

thanks this worked out really good as thrope made it :)

I was hoping to do it without having to redirecting it :)

thanks for both of you..

 

actually im doing a multiple language page  so that would be the easiest way for me to do it :P

for example id 1 would be English id 2 would be Spanish etc

 

 

 

 

sorry i didn't get what you mean

at the moment I have it this way:

 

index.php?id=1 will show the English content from the database

index.php?id=2 will show the Spanish content from the database..

 

I know this wouldn't be good if you got more than one page website...

That's what I mean like if you have like: home about us contact services portfolio. You could have it in a database like this.

 

home
$id = 1
about us
$id = 2
contact
$id = 3
etc...

Then you could have language settings for all of those with a simple $_GET string. Just a thought it would make it a lot easier to use. I would also recommend that you use an apache mod_rewrite for SEO purposes. Again they are all best practices and it is totally up to you.

Thanks,

Colton Wagner

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.