Forum Moderators: coopster

Message Too Old, No Replies

query with next/prev using iframes

displaying pages inside iframes

         

Lighthater

3:13 am on May 12, 2004 (gmt 0)

10+ Year Member



I've been racking my brain and staring at a book for days now. I'm not much of a coder, so when I can't find good examples, I get lost quickly.

What I'm looking to do is create a page that queries my mysql database and displays a page inside an iframe. When the user clicks on a next button, then will be forwarded the next result. Here is the details:

Database: com
Table: koc
Field1: id (just an ID field, auto increment)
Field2: link (the link to the document or to the URL)
Field3: name (Name of the site or person who posted it)

This is a very simple part of my plan, but I need a kick start. If anyone can help, I'd be most appreciatative. I can't seem to get a good start on this.

[edited by: jatar_k at 5:01 am (utc) on May 12, 2004]
[edit reason] sorry no personal urls thanks [/edit]

Lighthater

11:53 am on May 12, 2004 (gmt 0)

10+ Year Member



Ok, no personal URLs.. how can I show an example of the page? :(

I guess if you are interested, I can email the link. I purposely put it on a "testing" site where no other content is, trying to not advertise anything.

httpwebwitch

4:25 pm on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One solution is to print PHP results into a javascript array, then have your "next" button load content into the iframe based on that. It would be easy to make a "previous" button too, and add some logic to prevent going below 0 or above the max number of items.

The code below isn't tested, but it ought to get you started.


<script>
pagenum=0;
<?php
$i=0;
$result=mysql_query("SELECT * FROM Database_table");
while ($row=mysql_fetch_array($result)){
print("links[".$i."]=".$row['link']."\n");
$i++;
}
?>
</script>

<iframe id='pages'>
<BR>
<input type='button' value='prev' onClick='pagenum--;pages.location.href=links[pagenum]'>
<input type='button' value='next' onClick='pagenum++;pages.location.href=links[pagenum]'>

You might also tidy up the code by making a javascript function goto(), where the argument is 1 (next page) or -1 (prev page)

good luck!

Lighthater

5:23 am on May 13, 2004 (gmt 0)

10+ Year Member



wow, thats a bit over my head unfortunately. I'll see what I can do though.

Lighthater

9:43 pm on May 14, 2004 (gmt 0)

10+ Year Member



ok, I got lost with http's idea.. but maybe someone can help me out a bit here. I want to use the next buttons I have here and display the link inside the iframe. I don't know how to get the link alone in a query. If I can make it select the current link for that page, I could use the variable as the source for the iframe.

<?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 = 1;

// 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
echo "<center>";
$sql = mysql_query("SELECT * FROM koc LIMIT $from, $max_results");

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

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM koc"),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 Link<br />";

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

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

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

echo "</center>";

?>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Clicker by Lighthater</title>
</head>

<body>

<p align="center"><iframe name="iframe" width="640" height="480" src="<?php echo $UNKNOWN_VARIABLE>">
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe></p>

</body>

</html>
<?
echo "Link #$page";
?>

Lighthater

11:11 pm on May 25, 2004 (gmt 0)

10+ Year Member



you can close this/delete this. It won't be any help to anyone and I've figured out how to do what I need. Thanks anyway.