Hey Bytes,
The website I'm working on is coming along just fine, and I'd like to thank all of you PHP folks who have been helping me out. I'm almost done with the coding!
I'm trying to get the data-basing code finished with. I've got my products, with lines of text next to it that serve as descriptions. With each of those entries, I have images. I've implemented the code for displaying the text, and I've also implemented the code for the images, but here is my problem:
The code is separate. The images are queried and displayed to the user in a list formation, and so is the text, but I don't have a clue how to put the two together.
Here is my code for displaying the text components: - <?php
-
include('books_login.php');
-
$connection=mysql_connect($mysql_host,$mysql_user,$mysql_password);
-
if(!$connection){
-
die("Could not connect to the database: <br/>". mysql_error());
-
}
-
$db_select=mysql_select_db($mysql_database);
-
if(!$db_select){
-
die("Could not select the database: <br/>".mysql_error());
-
}
-
-
// how many rows to show per page
-
$rowsPerPage = 10;
-
-
// by default we show first page
-
$pageNum = 1;
-
-
// if $_GET['page'] defined, use it as page number
-
if(isset($_GET['page']))
-
{
-
$pageNum = $_GET['page'];
-
}
-
-
// counting the offset
-
$offset = ($pageNum - 1) * $rowsPerPage;
-
-
$query = " SELECT * FROM air_registers" .
-
" LIMIT $offset, $rowsPerPage";
-
$result = mysql_query($query) or die('Error, query failed');
-
-
-
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
-
$type=$row["Type"];
-
$number=$row["Number"];
-
$desc=$row["Description"];
-
echo "<div id='type'><strong>Model Type: </strong>$type</div>";
-
echo "<div id='number'><strong>Model #: </strong>$number</div>";
-
echo "<br />";
-
echo "<div id='desc'><strong>Description: </strong>$desc</div>";
-
echo "<br />";
-
echo "<hr>";
-
}
-
// how many rows we have in database
-
$query = "SELECT COUNT(*) AS numrows FROM air_registers";
-
$result = mysql_query($query) or die('Error, query failed');
-
$row = mysql_fetch_array($result, MYSQL_ASSOC);
-
$numrows = $row['numrows'];
-
-
// how many pages we have when using paging?
-
$maxPage = ceil($numrows/$rowsPerPage);
-
-
// print the link to access each page
-
$self = $_SERVER['PHP_SELF'];
-
$nav = '';
-
-
for($page = 1; $page <= $maxPage; $page++)
-
{
-
if ($page == $pageNum)
-
{
-
$nav .= " $page "; // no need to create a link to current page
-
}
-
else
-
{
-
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
-
}
-
}
-
// ... the previous code
-
-
// creating previous and next link
-
// plus the link to go straight to
-
// the first and last page
-
-
if ($pageNum > 1)
-
{
-
$page = $pageNum - 1;
-
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
-
-
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
-
}
-
else
-
{
-
$prev = ' '; // we're on page one, don't print previous link
-
$first = ' '; // nor the first page link
-
}
-
-
if ($pageNum < $maxPage)
-
{
-
$page = $pageNum + 1;
-
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
-
-
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
-
}
-
else
-
{
-
$next = ' '; // we're on the last page, don't print next link
-
$last = ' '; // nor the last page link
-
}
-
-
// print the navigation link
-
echo $first . $prev . $nav . $next . $last;
-
-
mysql_close($connection);
-
?>
This works fine and displays my text information.
Here is the code for the image output to the user: - <?php
-
include('books_login.php');
-
include('pix.php');
-
$connection=mysql_connect($mysql_host,$mysql_user,$mysql_password);
-
if(!$connection){
-
die("Could not connect to the database: <br/>". mysql_error());
-
}
-
$db_select=mysql_select_db($mysql_database);
-
if(!$db_select){
-
die("Could not select the database: <br/>".mysql_error());
-
}
-
-
$strSQL = "select * from pix";
-
$rsPix = mysql_query($strSQL);
-
$numRows = mysql_numrows($rsPix);
-
$i = 0;
-
-
while($i < $numRows){
-
?>
-
<img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
-
<?php
-
$i++;
-
}
-
?>
-
-
And the code above refers to pix.php: - <?php
-
include('books_login.php');
-
$connection=mysql_connect($mysql_host,$mysql_user,$mysql_password);
-
if(!$connection){
-
die("Could not connect to the database: <br/>". mysql_error());
-
}
-
$db_select=mysql_select_db($mysql_database);
-
if(!$db_select){
-
die("Could not select the database: <br/>".mysql_error());
-
}
-
if (IsSet($_GET['pixID'])){
-
$gotten = @mysql_query("select imgdata from pix where pixID = ".$_GET['pixID']);
-
header("Content-type: image/jpeg");
-
while ($row = mysql_fetch_array($gotten,MYSQL_ASSOC))
-
{
-
print $row['imgdata'];
-
-
}
-
mysql_free_result($gotten);
-
}
-
?>
I have two tables in my mysql DB:
-one for the images (composed of a BLOB field and an int field for Unique Key)
-one for the text (composed of three or four varchar fields and an int field for Unique Key)
I believe I'm supposed to link these tables together using keys... is that correct? Then maybe I could write code that will utilize the two linked tables? I'm not sure what direction I should go here.
8 2076
You know, I think I almost have this figured out. I'll post new code when I solve the problem.
Assuming your ID (unique key) columns are a reliable relationship between the tables, simply perform a query to get your image data (as well as getting it's ID). Then use this ID in your second query for the details (using the ID as a WHERE clause).
You get me? Sorry if I'm a little hazy, I was at a wedding yesterday.
Hey Markus, thanks for the reply.
I've tried instead just making one table with all of my different items (I merged the imgdata with all of my varchars into one table). Is this being lazy? I understand that this method is poor normalization, but it seems easiest for me right now. Here is what I tried (and its not working): -
$query = " SELECT * FROM air_registers" .
-
" LIMIT $offset, $rowsPerPage";
-
$result = mysql_query($query) or die('Error, query failed');
-
-
-
while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
-
$thumb=$row["Thumbnail"];
-
$type=$row["Type"];
-
$number=$row["Number"];
-
$desc=$row["Description"];
-
$i = 0;
-
echo "<div id='type'><strong>Model Type: </strong>$type</div>";
-
echo "<div id='number'><strong>Model #: </strong>$number</div>";
-
echo "<br />";
-
-
echo '<img src="pix.php?pixID=<?php echo mysql_result($result,$i,"pixID"); ?>"/>';
-
-
echo "<br />";
-
echo "<div id='desc'><strong>Description: </strong>$desc</div>";
-
echo "<br />";
-
echo "<hr>";
-
$i++;
Everything in bold is what was taken from my old list.php file. I know this is sloppy, but I'm trying to make it work. I'm very unhappy with the way it looks now, so more than likely I'll try to query two different tables (like you suggested Markus).
Hey all,
I ended up just dropping the images from my database. I put them in the file manager, and I'm using this bit of code to pull them out and onto the page: - echo "<img src=\"".$pixID."\" />"
$pixID is a field in my database that refers to the image name. This works fine for now, and I'll look into using the BLOB field later. I'm going to look through a lot of documentation and tutorials before I try that method again (the method that utilizes a BLOB field with images in the database instead of the file manager). Question:
If I have my images in the file manager, can I still implement an extension that will automatically re-size my pictures? I was looking at a GD extension provided by Atli in post #2 of this thread. Can I still write a PHP script that will change the picture size before it is rendered using this GD extension? Or is that a problem because my pictures are on the file manager instead of the MySQL database?
@tharden3
You can still use GD on files that are located on your server. Although, providing 'on-the-fly' resized images is very resource intensive. The smarter thing to do is save a resized version and the original.
@Markus
Ok, thats what I've been doing for now. I have a "full version" of each image and a re-sized "thumbnail" version. I've been using GIMP to re-size each image before I put it on the server. Is that ok for now? Or is there something quicker I could be doing? Anything to cut down on my production time is welcome ;)
@tharden3
You could cut out GIMP and upload the images through a form, which PHP would then create a resized image, and save them both.
@Markus
I'll try this out and post my results.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rob Ratcliff |
last post by:
I'm compiling the latest version of a CORBA ORB called MICO on a Cray
X1. It makes heavy use of templates and namespaces.
Up until the link step, the C++ source code compiled flawlessly. But,
when...
|
by: Ken |
last post by:
I have a win 2000 database of autographs and scanned photos. They are
in the SAME directory. In the table, my "ImagePath" text field shows
JUST the image name (i.e. "blank.jpg"). I have an image...
|
by: Daveyk0 |
last post by:
Hello there,
I have a front end database that I have recently made very many changes
to to allow off-line use. I keep copies of the databases on my hard
drive and link to them rather than the...
|
by: dskillingstad |
last post by:
I've been struggling with this problem for some time and have tried
multiple solutions with no luck.
Let me start with, I'm a novice at Access and I'm not looking for
someones help to design my...
|
by: chrisse_2 |
last post by:
Hi,
All the records in my database will contain at least one picture. At
the moment all the images are part of the database as ole objects
although the database is way to big and there is only...
|
by: Objectifnet |
last post by:
What I really want to do is to be able to link two pages together using an ID, The table involved displays an image stored on the File Server that has the image details stored in the Database called....
|
by: kavithadevan |
last post by:
Hi,
I am creating websites in my event search form i am have 2 options(which is in radio button)one is countryname and another one is state name with search field(Its in first table).If i run my...
|
by: naveenmurthy |
last post by:
Hello All,
I have created a .mht file in following format.
1. The .mht file contains following htmls.
a. MHTLinkingProblem.html
b. Left.html
c. Right.html
d. Start.html
|
by: premprakashbhati |
last post by:
hi, good evening..
i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button()
here is the code ...its work fine...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
|
by: jack2019x |
last post by:
hello, Is there code or static lib for hook swapchain present?
I wanna hook dxgi swapchain present for dx11 and dx9.
| |