Jump to content

[SOLVED] Basic PHP Paging: (Showing mySQL results in one page per row)


webmaster1

Recommended Posts

Hi All,

 

I want to output the contents of a mySQL table into an individual page per each row.

 

The user will initially be presented with a page of thumbnails which when clicked will link to a page consisting of additional information for that product.

 

Here's the page that displays the thumnails:

 

<?php

include("dbinfo.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT imageurl1 FROM test ORDER BY date";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

echo "<b><center>Output Thumbs</center></b><br><br>";

$i=0;
while ($i < $num) {

$imageurl1=mysql_result($result,$i,"imageurl1");

echo "<img src='$imageurl1' width='250' height='188'>";

$i++;
}

?>

 

If anyone is familiar with paging I was hoping you could advise me of what I need to be looking at next.  :)

Link to comment
Share on other sites

The following page shows the entire output to be displayed to the user when the thumbnail is clicked.

 

<?php

include("dbinfo.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM test ORDER BY date";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

$i=0;
while ($i < $num) {

$index=mysql_result($result,$i,"index");
$make=mysql_result($result,$i,"make");
$model=mysql_result($result,$i,"model");
$price=mysql_result($result,$i,"price");
$engine=mysql_result($result,$i,"engine");
$transmission=mysql_result($result,$i,"transmission");
$year=mysql_result($result,$i,"year");
$colour=mysql_result($result,$i,"colour");
$mileagem=mysql_result($result,$i,"mileagem");
$mileagekm=mysql_result($result,$i,"mileagekm");
$owners=mysql_result($result,$i,"owners");
$doors=mysql_result($result,$i,"doors");
$location=mysql_result($result,$i,"location");
$info=mysql_result($result,$i,"info");
$date=mysql_result($result,$i,"date");
$ipaddress=mysql_result($result,$i,"ipaddress");
$imageurl1=mysql_result($result,$i,"imageurl1");
$imageurl2=mysql_result($result,$i,"imageurl2");
$imageurl3=mysql_result($result,$i,"imageurl3");


echo "
$index</br>
$make</br>
$model</br>
$price</br>
$engine</br>
$transmission</br>
$year</br>
$colour</br>
$mileagem</br>
$mileagekm</br>
$owners</br>
$doors</br>
$location</br>
$info</br>
$date</br>
$ipaddress</br>
<img src='$imageurl1' width='250' height='188'>
<img src='$imageurl2' width='250' height='188'>
<img src='$imageurl3' width='250' height='188'>
</br>
<hr><hr>
</br>
     ";

$i++;
}

?>

This displays all of the mySQL table with a listing of consecutive records.

Link to comment
Share on other sites

I've worked the above tutorial successfully but it wasn't what I was looking for at all.  :(

 

Here's a diagram if it helps:

 

pagingtq1.jpg

 

I geuss I'm not looking for pagination at all. I simply need a row of data outputted into its own page after selecting a thumbnail link. Any ideas or at least a clarification of the terminology and key words I need to be searching under?

Link to comment
Share on other sites

okay well you could just like, have thumbnail.php run a query to grab all the info and echo out all the thumbnails in a loop, but make it them links, passing the filename in the url.  Or some id associated with it, or whatever.  Then when you click the link it takes you to output.php?foo=bar and in output.php you would use $_GET['foo'] to display the picture.  If you passed some id you could run a query to grab the file info based on the id or if you passed the file name just echo an img with the GET var as the src or whatever.

Link to comment
Share on other sites

Righto, here's the looped thumbnails with a link bit:

 

<?php

include("dbinfo.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT imageurl1 FROM test ORDER BY date";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

echo "<b><center>Output Thumbs</center></b><br><br>";

$i=0;
while ($i < $num) {

$imageurl1=mysql_result($result,$i,"imageurl1");

echo "<a href="SOMELINK"><img src='$imageurl1' width='250' height='188'><a>";

//echo "$imageurl1";

$i++;
}

?>

 

The output.php?foo=bar  and $_GET['foo'] concept is completley alien to me though. Is there a specific terminology for this that I can research/google?

 

 

Link to comment
Share on other sites

Wow, I honestly didn't think it would be that simple.

 

I set page 1 to send bar and then defined bar as a variable in page 2 which I then added to my query. Easy as pie when you know how...

 

$query="SELECT * FROM test WHERE urn = '$geturn' ORDER BY date";

 

I now have the output functioning exactly as illustrated in the previously posted diagram. Thanks Crayon!  :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.