title: How can I create a dynamic URL in php?
body: <p>I am new in PHP and MySQL.</p>
  
  <p>Here's what I've tried so far and I can't understand how to make URL with PHP.</p>
  
  <p>What I want to do is to create a dynamic web page about a particular book. I already created and have some data in my MySQL database to play with.</p>
  
  <p>I've got a function to clear the special characters in the book titles.</p>
  
  <pre><code>function seo($s) {
  $tr = array('ş','Ş','ı','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç');
  $eng = array('s','s','i','i','g','g','u','u','o','o','c','c');
  $s = str_replace($tr,$eng,$s);
  $s = strtolower($s);
  $s = preg_replace('/&amp;.+?;/', '', $s);
  $s = preg_replace('/[^%a-z0-9 _-]/', '', $s);
  $s = preg_replace('/\s+/', '-', $s);
  $s = preg_replace('|-+|', '-', $s);
  $s = trim($s, '-');
  
  return $s;
  }
  </code></pre>
  
  <p>Example</p>
  
  <pre><code>echo seo($booktitle);
  </code></pre>
  
  <p>.htaccess</p>
  
  <pre><code>Options +FollowSymLinks
  RewriteEngine on
  RewriteRule ^/(.*)-(.*)$ /book.php?id=$1 [L,NC]
  </code></pre>
  
  <p>Link type</p>
  
  <pre><code>echo "&lt;a href='http://sitename.com/".$bookid."-".seo($booktitle)."'&gt;".$booktitle."&lt;/a&gt;";
  </code></pre>
  
  <p>Output I want</p>
  
  <pre><code>http://sitename.com/id-book-title    
  </code></pre>
  
  <p>The thing is, I don't understand how I can pass the $bookid from the url to the php itself dynamically. I think I need to retrieve book_id from my database and assign it to $bookid variable, is that correct? But how can I connect it to the URL?</p>
  
  <p>For instance, when I type the url <a href="http://sitename.com/5-the-trial" rel="nofollow">http://sitename.com/5-the-trial</a> I need to get the page for the book that has the id of 5.</p>
  
  <p>What's missing here? Can you guide me to the right direction to create dynamic urls? I am both in need of guidance (learn this, search that, etc) and a specific answer to my question, if that's possible.</p>