create dynamic link without creating new php page??

Thread Solved

Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

create dynamic link without creating new php page??

 
0
  #1
Apr 16th, 2009
hi,

I am created 3 tables for
1> category
2> subcategory
3> projectdetail

In my website folder structure

root-index.php, header.php footer.php

folder- about -index.php and other files

folder - project- index.php

folder - err- 404.php

In my php page project/index.php

i make left column dynamic, i.e call value from table

e.g

School project ( this is category) and href link is project/School project
xyz (subcategory) and href link is project/xyz
abc and href link is project/abc

College project
www
yyy

I want do like when click on link project/School project
It should display that project
but id gives me error 404 page.
Not to create folder for school project or xyz or abc

How to do like when click on link it should display that value from database.
How create dynamic link without creating new php page??
How to do that??


my .htaccess file is

Options +FollowSymLinks

RewriteEngine On
ErrorDocument 404 http://www.aaa.com/err/404.html
RewriteRule ^([^.]+).html$ $1.php [QSA,L]
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #2
Apr 16th, 2009
you can create a dynamic link on the bases of field name,id like you have project.php and there are three projects in db
e.g
fetch from db and put in a variable
  1. $project_name='english';
  2. $project_name='math';
  3. $project_name='science';

for three courses saved in database

now you want to show details on project.php with different urls

so link will be
<a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a> as href or page action

and use htacces file
for url rewriting like

  1. RewriteEngine on
  2. RewriteBase /
  3.  
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteRule ^projects/(.*)/$ project.php?project_id=$1 [L]

request that project id in new page as
$project_id=$_REQUEST['project_id'];
and do what ever you want

now you are using one php page project.php
but there will be three different links

www.mysite.com/projects/english/
www.mysite.com/projects/math/
www.mysite.com/projects/science/


these examples are just to give you idea
Last edited by peter_budo; Apr 16th, 2009 at 7:57 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #3
Apr 16th, 2009
hi,

In my folder - project- index.php

Fetching all data
  1. <a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a>
It shows like

link:- www.mysite.com/projects/School project/ name:- School project
link:- www.mysite.com/projects/xyz/ name:- xyz
link:- www.mysite.com/projects/abc/ name:- abc


My .htaccess file
  1. Options +FollowSymlinks
  2.  
  3. RewriteEngine On
  4. RewriteBase /
  5.  
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteCond %{REQUEST_FILENAME} !-f
  8. RewriteRule ^projects/(.*)/$ index.php?project_id=$1 [L]
  9.  
  10. RewriteRule ^([^.]+).html$ $1.php [QSA,L]
  11. RewriteRule ../index.html [L]

when click on link it gives error
The requested URL was not found on this server.
Last edited by Aamit; Apr 16th, 2009 at 5:49 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 9
Reputation: rush1 is an unknown quantity at this point 
Solved Threads: 1
rush1 rush1 is offline Offline
Newbie Poster

Re: create dynamic link without creating new php page??

 
0
  #4
Apr 16th, 2009
My question is you are giving $project_name in link
so how you get
  1. $project_id=$_REQUEST['project_id'];

please explain??
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #5
Apr 16th, 2009
No you are not getting my point

Look when you are using link for example

  1. <a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a>

the link made by this should be as

www.mysite.com/projects/School-project/

the spaces are not allowed in url so if you have space in your project name use string replace function and replace them with "-" not underscors as "-" is more effective for search engines.

when we will go at htacces file as

Options +FollowSymlinks 

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^projects/(.*)/$ index.php?project_id=$1 [L]

understand the meaning of bold url rewrite rule

that means when it got www.mysite.com/projects/ and (.*)=parameter that passes and that is project name means

projects/(.*)=www.mysite.com/projects/School-project/

then redirect this url to index.php and the project name that is 1st parameter put the value of that in project_id variable

means

at this stage project_id='School-project';

now request the project_id variable on detail page

$project_id=$_REQUEST['project_id'];
this $project_id is just variable name it contains the value of project name not ID

now again apply string replace function on $project_id and replace that "-" with "%" that will help you to apply LIKE command for sql quesry

after apply replace function it will be

$proj_name="school%project";
now apply the select query like
select project_id from table-project where project_name like '$proj_name% or 

project_name like 'school%name%'
that will match each word

now you will get the ID of that project name and use that if for your required results.

All this process is for proper url re-writing for dynamic urls
Last edited by peter_budo; Apr 16th, 2009 at 7:59 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #6
Apr 16th, 2009
hi,
can you please explain briefly...with example...
I am doing same as you suggested...
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #7
Apr 16th, 2009
Aamit i can explain it briefly with example but now i have to go. if you can wait i can send you the example tomorrow.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #8
Apr 16th, 2009
can you wait
Last edited by BzzBee; Apr 16th, 2009 at 9:30 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #9
Apr 16th, 2009
Yes. sure

Can you post full code with htaccess??
Last edited by Aamit; Apr 16th, 2009 at 9:34 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 257
Reputation: BzzBee is an unknown quantity at this point 
Solved Threads: 37
BzzBee BzzBee is offline Offline
Posting Whiz in Training

Re: create dynamic link without creating new php page??

 
0
  #10
Apr 17th, 2009
hello amit. i have done it for you. i am attaching a folder. use it at your localhost. and tell me whats the results.

i have made a database with single table. database backup is also in the folder. just use the database and run the file.

htaccess file is also there. All the work is done. just see the folder.

i am here for further help
Last edited by BzzBee; Apr 17th, 2009 at 2:14 am.
Attached Files
File Type: zip project_test.zip (2.8 KB, 22 views)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC