Jump to content

How to move value to next page


php_guest

Recommended Posts

I have a list of 300 products inside one page:

T-shirts

Trousers

Socks

...

 

Every product is a link to the next page. I would like to assign the value of variable for each product so I can pull in next page right information from table Products.

Due SEO I would like to keep URL in following format: www.sitename.com/productname

 

So my question is how to send a value of variable of a product to which user click to the next page?

 

Will code read from www.sitename.com/productname once beeing on next page which productID to pull from database?

Link to comment
Share on other sites

Just a little warning, first off not all hosts will allow mod rewrite, second off i believe it can cause problems with some search engines as it looks for a directory then and not a file, and third if the user or you try and use

 

site.com/productname/

 

it won't work it has to be

 

site.com/productname

Link to comment
Share on other sites

Just a little warning, first off not all hosts will allow mod rewrite, second off i believe it can cause problems with some search engines as it looks for a directory then and not a file, and third if the user or you try and use

 

site.com/productname/

 

it won't work it has to be

 

site.com/productname

 

depend of that, is there any better solution how to move value to next page in this case?

Link to comment
Share on other sites

Just a little warning, first off not all hosts will allow mod rewrite

 

Pretty much all of them do these days. If they don't, it's time to get a new host, as that host is living in the dark ages.

 

second off i believe it can cause problems with some search engines as it looks for a directory then and not a file

 

Search engines have no clue whether the directory exists or not. They don't see the server, they only see the data that the server feeds to them. Mod rewrite is set up on the server, and any rewriting is done internally before being sent to the search engines (or user). So whether a directory exists, or whether mod rewrite just makes it look like a directory exists, it doesn't really matter.

 

third if the user or you try and use

 

site.com/productname/

 

it won't work it has to be

 

site.com/productname

 

If the mod rewrite is written properly, both can work.

Link to comment
Share on other sites

Search engines have no clue whether the directory exists or not. They don't see the server, they only see the data that the server feeds to them. Mod rewrite is set up on the server, and any rewriting is done internally before being sent to the search engines (or user). So whether a directory exists, or whether mod rewrite just makes it look like a directory exists, it doesn't really matter.

 

No, that is not what i meant when you use it in links and/or submit them as pages in your site map it can make the search engine believe it is a directory and in effect come up with a 404

Link to comment
Share on other sites

I found also one another solution with $_SERVER['REQUEST_URI'] function. Which one do you think is better.

 

I just don't know now how to change www.mysite.com/product.php/productname into www.mysite.com/productname. Please tell me how to change following code to get this format of url. Showing product page is inside product.php.

 

//Insert product into DB
<?php
    $productName="laptop";
    $urlID="/product.php"."/".$productName;
    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    $db = mysql_select_db("DBname", $con);
    mysql_query("INSERT INTO products (urlID, productName) VALUES ('$urlID', '$productName')")
    or die(mysql_error());
?>

//productsList.php
<?php

    $con = mysql_connect("localhost", "root", "") or die(mysql_error());
    $db = mysql_select_db("DBname", $con);
    $query="SELECT * FROM products";
    $result=mysql_query($query);
    while ( $row = mysql_fetch_assoc($result))
    {
            extract ($row);
            echo "<a href='/product.php/$productName'>$productName</a>";
      echo "<br />";
    }
?>

//product.php
<?php
$urlID=$_SERVER['REQUEST_URI'];
$con = mysql_connect("localhost", "root", "") or die(mysql_error());
    $db = mysql_select_db("DBname", $con);
    $result=mysql_query("SELECT * FROM products WHERE urlID='$urlID'");
    $row = mysql_fetch_assoc($result);
    $product=$row[productName];
    echo $product;
?>

Link to comment
Share on other sites

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.