Php help

They have: 4 posts

Joined: Dec 2005

http://www.abmagdesign.com/
What I am trying to do is have a Google like page with the numbers displayed on the bottom.
Each number is a link to a specific html page.

I have this Mysql table call tbl_pages.

I have an insert.php page.
this is the code that includes my db connection....

<?php

include 'db.php';


for(
$i = 1; $i <= 20; $i++){
   
mysql_query("INSERT INTO pages (title) VALUES ('Item $i')");
    echo
"Item $i inserted into db <br />";
}
?>

This inserts 20 items into the table.

<?php


// Database Connection
include 'db.php';

// If current page number, use it
// if not, set one!

if(!isset($_GET['page'])){
   
$page = 1;
} else {
   
$page = $_GET['page'];
}

// Define the number of results per page
$max_results = 10;

// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);

// Perform MySQL query on only the current page number's results

$sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");

while(
$row = mysql_fetch_array($sql)){
   
// Build your formatted results here.
   
echo $row['title']."<br />";
}

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";

// Build Previous Link
if($page > 1){
   
$prev = ($page - 1);
    echo
"<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for(
$i = 1; $i <= $total_pages; $i++){
    if((
$page) == $i){
        echo
"$i ";
        } else {
            echo
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Build Next Link
if($page < $total_pages){
   
$next = ($page + 1);
    echo
"<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo
"</center>";
?>

This page does all the work and returns th link and items but here's my problem.
I have html pages that I created prior to wanting to use This PHP code and would like use the pages I already have.
I would like the link to show up on the bottom of these pages and then have the numbers link to specific pages.
I am a beginner with PHP and would appreciate some help from the experts.

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

I believe you can set your .htaccess file to interpret your html pages as php scripts, then stick your code in the html page.

Just add the following line:

AddType application/x-httpd-php .php .html

Or, if you already have something like this:

AddType application/x-httpd-php .php

...then just add .html to the end (make sure you include a space)

They have: 4 posts

Joined: Dec 2005

I am fairly new to this .
How would you do this if you can show me how exactly that would be good.

They have: 4 posts

Joined: Dec 2005

By the way i checked out your websites you guys are good.

demonhale's picture

He has: 3,278 posts

Joined: May 2005

you could save your html pages as php, meaning save an index.html for example as index.php ; wouldnt affect any codes inside the original. But in this way you could use the

<?php
include filename
?>
tags in there... Im writing this fast now coz I got to go... I hope I was right...

timjpriebe's picture

He has: 2,667 posts

Joined: Dec 2004

Check your server to see if you already have a .htaccess file. If so, just modify it like I posted above. If not, then create a blank text file on your machine with notepad or some plain text editor. Then just add that line in. Save it as htaccess.txt, then upload it to your web server. Change the file name on the server to .htaccess, and you should be all set.

Of course, this assumes your server is Unix or Linux, and that it allows htaccess files. Most are Unix/Linus and most of those do.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.