Jump to content

Changing item # to item name in url


laflair13

Recommended Posts

Well I am looking to change this url

 

http://website.com/product.php?Item=2369

 

to

 

http://website.com/product.php?Item=Item-Name

 

 

Heres a snip of the code that handles that.

 

<?php

include_once('mysql_connect.php');

$id = (int)$_GET['Item'];

?>

 

any help would be appreciated.

 

Link to comment
Share on other sites

I guess you use ID with SQL WHERE clause, yes?

 

Instead of something like

$id = (int)$_GET['Item'];
$query = "SELECT * FROM Table WHERE id = {$id}";

 

you can use

$name = $_GET['item'];
"SELECT * FROM Table WHERE name = {$name}"

 

Btw, always use mysql_real_escape() while inserting POST/GET data into SQL queries.

Link to comment
Share on other sites

Try this

 

<?php
$word="this is the spaced word"; 
$word2 = str_replace( ' ', '-', $word ); 
echo $word; echo "<br />";
echo $word2;echo "<br />";
?>
<a href="?id=<?php echo $word2; ?>">click</a><br />

<?php


$string = $_GET[id];
$string2 = str_replace( '-', ' ', $string ); 

echo $string2;
//use string two to query your data


?>

Link to comment
Share on other sites

well i think you have a page where it displays all the products which they have a link to the product_name=item-name correct ?

 

so before we do this we will change all the products link to this

<?php
$word = $row['itemname']; 
$word2 = str_replace( ' ', '-', $word ); 
?>
<a href="?id=<?php echo $word2; ?>">See Product</a><br />



<?php
//this is the other page
$string = $_GET[itemname];
$string2 = str_replace( '-', ' ', $string ); 

echo $string2;
//use string two to query your data

"SELECT * FROM Table WHERE name = {$string2}"

?>

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.