0

My Question is: How can I show it http://localhost/jakir1/banner2/test.php/title-3 instead of http://localhost/jakir1/banner2/test.php?slug=title-3

When i click

  1. title 1
  2. title 2
  3. title 3

Its Showed Output

Here is My Code:

<table border="1">
  <tr>
    <td>
     Product Name 
   </td>
    <td>
    Description 
   </td>
   </tr>
   <?php $sql = "SELECT * FROM marchant_item ORDER BY id DESC";
         $display =  mysqli_query($db, $sql);
         while ($row = mysqli_fetch_array($display)) { ?>
            <tr>
                <td><a href="test.php?slug=<?php echo $row['slug']; ?>"><?php echo $row['item_name']; ?></a></td>
                <td>
                    <?php echo $row['description']; ?>
                </td>
            </tr>
   <?php      }
    ?>
</table>

<?php
if (isset($_GET['slug'])) {
$data = $_GET['slug'];
?>
<table border="1">
  <tr>
    <td>
     Product Name 
   </td>
    <td>
    category
   </td>
   </tr>
   <?php $sql = "SELECT * FROM marchant_item WHERE slug ='$data'";
         $display =  mysqli_query($db, $sql);
         while ($row = mysqli_fetch_array($display)) { ?>
            <tr>
                <td><?php echo $row['item_name']; ?></td>
                <td>
                    <?php echo $row['category']; ?>
                </td>
            </tr>
   <?php      }
    ?>

</table>
<?php
}
?>

Output: enter image description here

  • 1
    I don't really understand your question. The URL with the get argument (`.../test.php?slug=title-3`) is exactly what you reate with your php code. If you do not want that but some other URL, then just output another URL. What is the question here? – arkascha Jan 20 '19 at 19:40

1 Answers1

0

write this line in your .htaccess file-- RewriteRule ^test/([A-Za-z0-9-]+)?$ test.php?slug=$1 [NC]

update your code with

<td><a href="test/<?php echo $row['slug']; ?>"><?php echo $row['item_name']; ?></a></td>

and you get http://localhost/jakir1/banner2/test/title-3

1313
  • 1