vinpkl Posted December 12, 2008 Share Posted December 12, 2008 hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url explode function in while statement <?php $leftqry="select * from dealer_table where category_id=1"; $leftresult=mysql_query($leftqry); if(mysql_num_rows($leftresult)>0) { while($leftrow=mysql_fetch_array($leftresult)) { $url = 'products.php?dealer_id='. $leftrow['dealer_id'] . "&category_id=" . $leftrow['category_id']; list($shorturl) = explode('?', $url); //echo $shorturl; echo "<tr>"; echo "<td>" . "<a class='leftnav' href='$shorturl'>" .$leftrow['dealer_name']. "</a></td>"; echo "</tr>"; echo "<tr>"; echo "<td style='height:1px'><img src='images/left_nav_sep_dwn.gif' alt='' width='147' height='1' /></td>"; echo "</tr>"; } } ?> after url explode function i get the short url as http://localhost/vineet/products.php http://localhost/vineet/products.php http://localhost/vineet/products.php and when i click on these links i am redirected to products.php but i m not able to view the content related to dealer_id and category_id. there i get Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\xampp\htdocs\vineet\products.php on line 40 otherwise without using this method i m getting all the results fine. what should i write in products.php page so that i can get the result with url explode function. or is it possible with any other function to change my url to flat url http://localhost/vineet/products.php/dealerid/12/categoryid/2 to have every link with diferent dealer id and category id but without ?string vineet Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/ Share on other sites More sharing options...
Yesideez Posted December 12, 2008 Share Posted December 12, 2008 Why do you want to make your URLs shorter? If you change them they will no longer point to where they should be going and you'll either get page not found (error 404) or something completely different to what you want when you click links. Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713596 Share on other sites More sharing options...
vinpkl Posted December 12, 2008 Author Share Posted December 12, 2008 Why do you want to make your URLs shorter? If you change them they will no longer point to where they should be going and you'll either get page not found (error 404) or something completely different to what you want when you click links. hi yesideez i just want to make it search engine friendly. will it be possible to have the url like http://localhost/vineet/products/dealerid/12/categoryid/2 with any function without using .htaccess file vineet Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713597 Share on other sites More sharing options...
Yesideez Posted December 12, 2008 Share Posted December 12, 2008 If you want to change the URLs to look like that you'll have to use .htaccess to modify the rewrite engine. http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713603 Share on other sites More sharing options...
vinpkl Posted December 12, 2008 Author Share Posted December 12, 2008 If you want to change the URLs to look like that you'll have to use .htaccess to modify the rewrite engine. http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html hi yesideez if this is the only alternative we have then i wil have to go with it. vineet Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713607 Share on other sites More sharing options...
jcombs_31 Posted December 12, 2008 Share Posted December 12, 2008 If you want to change the URLs to look like that you'll have to use .htaccess to modify the rewrite engine. http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html hi yesideez if this is the only alternative we have then i wil have to go with it. vineet Yes. You still need the url variables to query the data properly but then have to re-write for friendly versions instead of ?variable1=239874&variable2=23087982374 Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713620 Share on other sites More sharing options...
vinpkl Posted December 12, 2008 Author Share Posted December 12, 2008 Yes. You still need the url variables to query the data properly but then have to re-write for friendly versions instead of ?variable1=239874&variable2=23087982374 hi jcombs can u help me with this. i am writing in my htaccess file the folowing lines but nothing hapening Options +FollowSymlinks RewriteEngine On RewriteRule ^products/([^/.]+)/([^/.]+)\.(htm¦html)$ /products.php?dealer_id=$1&category_id=$2 [L] still getting the same http://localhost/vineet/products.php?dealer_id=12&category_id=2 vineet Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713663 Share on other sites More sharing options...
Yesideez Posted December 12, 2008 Share Posted December 12, 2008 I've not played with mod_rewrite much myself but you don't specifyn for indivudl lines (you can but you'd need every permutation possible on your site which, well, I think you know how big your htaccess file would get. Just write a generic rle that would apply to all pages. Link to comment https://forums.phpfreaks.com/topic/136668-short-url-with-explode-function/#findComment-713708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.