how to get short url explode work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinpkl
    New Member
    • Oct 2008
    • 41

    how to get short url explode work

    hi all

    i want to use explode url for shotening my urls

    i have a url like
    Code:
    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
    Code:
    <?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
    Code:
    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
    Code:
    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.p hp" page so that i can get the result with url explode.


    vineet
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You are not getting a result from your query
    Originally posted by vinpkl
    Code:
    <?php 
    	    $leftqry="select * from dealer_table where category_id=1";
    		$leftresult=mysql_query($leftqry);
    vineet
    You are not making a DB connection so the last known will be used

    Comment

    • vinpkl
      New Member
      • Oct 2008
      • 41

      #3
      url explode

      Originally posted by code green
      You are not getting a result from your query
      You are not making a DB connection so the last known will be used
      hi code green

      i m making and using my db connection in config.php file which is included on top of all pages.

      vineet

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Lines 8 and 9 in your code make absolutely no sense.
        Why compile the link like you do in line 8 using data from your database, only to explode it and essentially strip all the data away?

        What exactly do you expect the explode function to do there?

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Originally posted by vinpkl
          hi code green

          i m making and using my db connection in config.php file which is included on top of all pages.

          vineet
          Nevertheless the error indicates that your result resource is empty.
          You should check the validity of the result resource in
          $leftresult=mys ql_query($leftq ry); before proceeding

          Sorry mods. My code tags don;t work

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by code green
            Nevertheless the error indicates that your result resource is empty.
            If I am not mistaken, the error he posted is from another page.
            Most likely caused by the links the explode function is messing up.
            The page expects GET parameters that it's not getting.

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, vinpkl.

              The only way to make what you're trying to do work is to use $url, not $shorturl. There is no way to make those URLs shorter without omitting vital information.

              You could try to make pretty URLs using mod_rewrite, though (Easy Mod Rewrite : mod_rewrite tutorial).

              Comment

              • vinpkl
                New Member
                • Oct 2008
                • 41

                #8
                Originally posted by pbmods
                Heya, vinpkl.

                The only way to make what you're trying to do work is to use $url, not $shorturl. There is no way to make those URLs shorter without omitting vital information.

                You could try to make pretty URLs using mod_rewrite, though (Easy Mod Rewrite : mod_rewrite tutorial).
                hi pbmods

                so i go the rewrite mode way.

                here is what i m writing in .htaccess
                Code:
                Options +FollowSymlinks
                RewriteEngine On
                RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)$ products.php?dealer_id=$1&category_id=$2 [L]
                when i type in my browser
                Code:
                http://localhost/vineet/products/dealer_id/12/category_id/2
                i get object not found error 404. can u help me with this.

                vineet

                Comment

                • vinpkl
                  New Member
                  • Oct 2008
                  • 41

                  #9
                  hi

                  with htaccess i m using
                  Code:
                  Options +FollowSymlinks
                  RewriteEngine On
                  RewriteRule ^/([a-zA-Z_]+)/([a-zA-Z_]+)$ products.php?dealer_id=$1&category_id=$2
                  to remove the query string of my url but not getting it to work

                  if i type in browser
                  Code:
                  http://localhost/vineet/products/dealer_id/12/category_id/2
                  i get error 404 object not found

                  vineet

                  Comment

                  Working...