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.

vineet

    ehm.. The parts that you separate from the url is crucial THat carries the information forward. If you do not include the section after the ? the script does not know the sections that you need, cannot perform the query and therefor throws an error if you try to retrieve the results.

    J.

      You have to pass the variable value in one way or another. If you absolutely have to hide it from the URL, you could do it as a form using a Post method, that'd just show you the destination address. Then you can pull the values out of the $_POST[] array, but if you've got multiple links per page your code could get really messy doing them all with forms.

      If that's the case, I'd probably write a class or a function to handle it so you don't have to hard code the form for every link.

        Write a Reply...