943,603 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 7896
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Apr 16th, 2009
0

create dynamic link without creating new php page??

Expand Post »
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]
Similar Threads
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Apr 16th, 2009
0

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

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
php Syntax (Toggle Plain Text)
  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

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 16th, 2009
0

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

hi,

In my folder - project- index.php

Fetching all data
PHP Syntax (Toggle Plain Text)
  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
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Apr 16th, 2009
0

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

My question is you are giving $project_name in link
so how you get
PHP Syntax (Toggle Plain Text)
  1. $project_id=$_REQUEST['project_id'];

please explain??
Reputation Points: 10
Solved Threads: 1
Newbie Poster
rush1 is offline Offline
9 posts
since Feb 2009
Apr 16th, 2009
0

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

No you are not getting my point

Look when you are using link for example

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 16th, 2009
0

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

hi,
can you please explain briefly...with example...
I am doing same as you suggested...
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Apr 16th, 2009
0

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

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.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 16th, 2009
0

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

can you wait
Last edited by BzzBee; Apr 16th, 2009 at 9:30 am.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009
Apr 16th, 2009
0

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

Yes. sure

Can you post full code with htaccess??
Last edited by Aamit; Apr 16th, 2009 at 9:34 am.
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Apr 17th, 2009
0

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

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
Attached Files
File Type: zip project_test.zip (2.8 KB, 328 views)
Last edited by BzzBee; Apr 17th, 2009 at 2:14 am.
Reputation Points: 16
Solved Threads: 48
Posting Whiz
BzzBee is offline Offline
327 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Pagination script not displaying records - why?
Next Thread in PHP Forum Timeline: php local time not working





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC