0

I've got rendered page with lots of items and i want to have item-specific page accessed by clicking the link

while($row = mysqli_fetch_array($result))
{
    echo "<h3><a href=\"".$row['Brand']."-".$row['Model']."\" class=\"text-info\">".$row['Brand']." ".$row['Model']."</a></h3>";
    //more details
}

So by clicking $row['Brand']-$row['Model'] I'd like to be redirected to the page with this item. Can i do that somehow? As the only way i know - is to insert new .php file and pass some unique item's id from SQL via URL or post request by that is not SEO-friendly way, so I'd like to avoid that.

Smern
  • 18,746
  • 21
  • 72
  • 90
Hunkeone
  • 505
  • 5
  • 11
  • You can have a standalone PHP script and use URL-rewriting (`.htaccess`) that will take the URL parts and translate (rewrite) them into `$_GET` parameters... Or You can use PHP routing. All depends on what setup, framework, cms you are using... But looking at the question as is, this is hard to answer or understand what is actually being asked... – shadyyx Oct 19 '13 at 16:15
  • This is how you should echo: `echo "

    {$row['Brand']} {$row['Model']}

    ";`
    – sybear Oct 19 '13 at 16:18
  • This is exactly what I've done :) – Hunkeone Oct 19 '13 at 21:59

2 Answers2

1

You'll need to use the rewrite in apache(assuming that's your webserver) This is a nice tutorial. Or look into using a framework that handles that for you. Something simple like CodeIgniter or Laravel.

Casey
  • 1,941
  • 3
  • 17
  • 30
0

You have to do it from the mysql_query function using where clause pointing to the column you to be filter the results.

    echo "<h3><a href=\"?brand=".$row['Brand']."&model=".$row['Model']."\" class=\"text-info\">".$row['Brand']." ".$row['Model']."</a></h3>";

$brand = (isset($_GET['brand'))?mysql_real_escape_string($_GET['brand']):'';
$model = (isset($_GET['model'))?mysql_real_escape_string($_GET['model']):'';
$query = "SELECT * FROM cars WHERE brand='$brand' AND model='$model'";

$result = mysql_query($query);
  • Why are You answering with code using [deprecated library](https://wiki.php.net/rfc/mysql_deprecation)? Check, [why shouldn't you use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – shadyyx Oct 19 '13 at 16:24
  • You wanna add letter i ? What dont you just put up your own answer instead? – Juan David Decano Oct 19 '13 at 16:32
  • Because I put a comment that this question has no clear answer. And your answers (all present here) are only shooting into the air since we do not know what framework/setup/cms he is using... – shadyyx Oct 19 '13 at 16:35