| | |
create dynamic link without creating new php page??
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
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]
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]
•
•
Join Date: Apr 2009
Posts: 257
Reputation:
Solved Threads: 37
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
for three courses saved in database
now you want to show details on project.php with different urls
so link will be
and use htacces file
for url rewriting like
request that project id in new page as
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
e.g
fetch from db and put in a variable
php Syntax (Toggle Plain Text)
$project_name='english'; $project_name='math'; $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 actionand use htacces file
for url rewriting like
PHP Syntax (Toggle Plain Text)
RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f 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.
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
hi,
In my folder - project- index.php
Fetching all data
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
when click on link it gives error
The requested URL was not found on this server.
In my folder - project- index.php
Fetching all data
PHP Syntax (Toggle Plain Text)
<a href="www.mysite.com/projects/<?$project_name?>/" ><?$project_name?></a>
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
PHP Syntax (Toggle Plain Text)
Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^projects/(.*)/$ index.php?project_id=$1 [L] RewriteRule ^([^.]+).html$ $1.php [QSA,L] 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.
•
•
Join Date: Feb 2009
Posts: 9
Reputation:
Solved Threads: 1
My question is you are giving $project_name in link
so how you get
please explain??
so how you get
PHP Syntax (Toggle Plain Text)
$project_id=$_REQUEST['project_id'];
please explain??
•
•
Join Date: Apr 2009
Posts: 257
Reputation:
Solved Threads: 37
No you are not getting my point
Look when you are using link for example
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
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
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
now apply the select query like
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
Look when you are using link for example
PHP Syntax (Toggle Plain Text)
<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%'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.
•
•
Join Date: Apr 2009
Posts: 257
Reputation:
Solved Threads: 37
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.
•
•
Join Date: Apr 2009
Posts: 257
Reputation:
Solved Threads: 37
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
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.
![]() |
Similar Threads
- The most famous CSS web sites galleries in the world (HTML and CSS)
- JSP database connectivity according to Model View Controller (MVC) Model 2 (JSP)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- creating a sticky form compatible with onChange (PHP)
- Apache (Linux Servers and Apache)
- dynamically update pages (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Template Engine Problem
- Next Thread: Sum all the values in one colum of a html table?
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl data database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link links login loop mail md5 menu mlm mod_rewrite multiple mysql mysql_real_escape_string oop parse paypal pdf php problem query radio random recursion regex remote replace script search searchbox server session sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video votedown web website xml youtube





