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
https://forums.phpfreaks.com/topic/259912-changing-item-to-item-name-in-url/
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.

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


?>

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}"

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.