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.

3
  • 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... Commented Oct 19, 2013 at 16:15
  • This is how you should echo: echo "<h3><a href='{$row['Brand']} - {$row['Model']}' class='text-info'>{$row['Brand']} {$row['Model']}</a></h3>"; Commented Oct 19, 2013 at 16:18
  • This is exactly what I've done :) Commented Oct 19, 2013 at 21:59

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! I hoped that it can be solved without web server config. but it is absolutely ok for me!
@Hunkeone You should accept the answer if this worked for you.
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);

3 Comments

Why are You answering with code using deprecated library? Check, why shouldn't you use mysql_* functions
You wanna add letter i ? What dont you just put up your own answer instead?
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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.