473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to get short url explode work

41
hi all

i want to use explode url for shotening my urls

i have a url like
Expand|Select|Wrap|Line Numbers
  1. http://localhost/vineet/products.php?dealer_id=12&category_id=2
  2.  
This is my navigation php code that has url explode function in while statement
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.         $leftqry="select * from dealer_table where category_id=1";
  3.         $leftresult=mysql_query($leftqry);
  4.         if(mysql_num_rows($leftresult)>0)
  5.         {
  6.             while($leftrow=mysql_fetch_array($leftresult))
  7.             {
  8.                 $url = 'products.php?dealer_id='. $leftrow['dealer_id'] . "&category_id=" . $leftrow['category_id'];
  9.                 list($shorturl) = explode('?', $url);
  10.                 //echo $shorturl;
  11.                 echo "<tr>";
  12.                 echo "<td>" . "<a class='leftnav' href='$shorturl'>" .$leftrow['dealer_name']. "</a></td>";
  13.                   echo "</tr>";
  14.                 echo "<tr>";
  15.                 echo "<td style='height:1px'><img src='images/left_nav_sep_dwn.gif' alt='' width='147' height='1' /></td>";
  16.                   echo "</tr>";
  17.             }
  18.         }
  19.         ?>
  20.  
  21.  
after url explode function i get the short url as
Expand|Select|Wrap|Line Numbers
  1. http://localhost/vineet/products.php
  2. http://localhost/vineet/products.php
  3. http://localhost/vineet/products.php
  4.  
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
Expand|Select|Wrap|Line Numbers
  1. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\xampp\htdocs\vineet\products.php on line 40
  2.  
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
Dec 12 '08 #1
8 5449
code green
1,726 Expert 1GB
You are not getting a result from your query
@vinpkl
You are not making a DB connection so the last known will be used
Dec 12 '08 #2
vinpkl
41
@code green
hi code green

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

vineet
Dec 12 '08 #3
Atli
5,058 Expert 4TB
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?
Dec 12 '08 #4
code green
1,726 Expert 1GB
@vinpkl
Nevertheless the error indicates that your result resource is empty.
You should check the validity of the result resource in
$leftresult=mysql_query($leftqry); before proceeding

Sorry mods. My code tags don;t work
Dec 12 '08 #5
Atli
5,058 Expert 4TB
@code green
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.
Dec 12 '08 #6
pbmods
5,821 Expert 4TB
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).
Dec 12 '08 #7
vinpkl
41
@pbmods
hi pbmods

so i go the rewrite mode way.

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

vineet
Dec 13 '08 #8
vinpkl
41
hi

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

if i type in browser
Expand|Select|Wrap|Line Numbers
  1. http://localhost/vineet/products/dealer_id/12/category_id/2
  2.  
i get error 404 object not found

vineet
Dec 13 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stijn Goris | last post by:
Hi all, $ttt = array(); $ttt = explode("-", "test-niet"); echo "$ttt | $ttt<br>"; Should give test | niet but gives
4
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
5
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
0
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
1
by: 848lu | last post by:
PHP - display from txt file with explode function hi, i am trying to display all data from a txt file with a function of explode but does not work..... <? #reads a text file outputs it to...
8
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
3
by: lbvox | last post by:
Hello, I have created this script, but I do not succeed to insert the function "explode ()" for being able to gain given following dates ---- ($host="hostname" / $msg="msg" /$date="date") <?php...
5
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
2
mikek12004
by: mikek12004 | last post by:
Initialy i wanted to create a short description of a text to be shown as preview, I found the following which worked OK $length = 35; // The number of words you want $words = explode(' ',...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.