473,320 Members | 1,572 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,320 software developers and data experts.

Using mod_rewrite to retrieve value in mySQL using php

1
Hi,

I am trying to convert urls from this format:

http://localhost/index.php?section=11
(where 11 is the id of the row in a table)

to this friendly url:

http://localhost/services.html (where 'services' is the sef id in the same row of the table)

I've noticed that I need to use rewritemap and a php script to access the mysql table since each row id can be retrieved by using the sef id.

The mapping of the text file works fine for me. I just want to use a PHP script instead since my supervisor asked me too (as an exercise, even though I know it's too heavy on the server to request the script each time - so I won't be using it in the end).

This is what I have so far in my conf file:

# load the map file
# RewriteMap pages txt:/etc/apache2/map.txt (i know this works)
RewriteMap pages prg:/etc/apache2/sef.php (this is my php script)

# if the request isn't for a real file
RewriteCond %{SCRIPT_FILENAME} !-f
# and a real directory
RewriteCond %{SCRIPT_FILENAME} !-d
# grab the directory name and get the id from the map file.
# it defaults to 0 if it's no found
RewriteRule ^/(.*).html/?$ /index.php?section=${pages:$1|0} [L]

In my sef.php file:

<?php

@$db = new mysqli('localhost','username','password','db');

$query = "Select id from expv5_section where sefurl = 'services'";
//On the line above, services will be an input the user types in the URL but I haven't
//got to that stage yet.

$result = $db->query($query);

$row = $result->fetch_assoc();
return $row['id'];

?>

But this doesn't seem to work. I know the php file returns the right id too. I think it doesn't like the following line, because my apache server doesn't even restart when I add it:

RewriteMap pages prg:/etc/apache2/sef.php

but I don't know what else the problem could be. Should I take a different approach with mod_rewrite?

I've googled for the past few hours and the more I read the more I'm confused.
Each time I stumble across this site for problems I always find it's useful, so I do hope someone can help me out. :0)

Many thanks.
Apr 12 '07 #1
0 3345

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

Similar topics

3
by: R.G. Vervoort | last post by:
I would like to select an option in a pulldown, select a record in a mysql database depending on the pulldown selection and then put the data from the record in the textfields. I can retrieve...
1
by: Westcoast Sheri | last post by:
Hello. How do I do this: If a visitor types in any number after my url, I want mod_rewrite to convert it to my url/anotherpage.html?number=number_visitor_typed Example: ...
0
by: AJ Shankar | last post by:
Hi, In the C API, is there any way to execute a query, store all the results, and somehow find the maximum realized width for each of the fields before fetching each row? Otherwise there is no...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
0
by: Allan Kim Jensen | last post by:
Hello, I am trying to retrieve data from a MySql database using ASP.net, and it works fine when putting the result into a gridview (Code provided in the end of this mail). However, I'd like...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
4
chumlyumly
by: chumlyumly | last post by:
Hi - I'm working with PHP5 MySQL Mac OSX I've developed two pages where a user can input his/her info, which goes to a MySQL database. The first page is supposed to pass the newly created...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.