473,856 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linking Image Table w/ Text Table

tharden3
916 Contributor
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:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('books_login.php');
  3. $connection=mysql_connect($mysql_host,$mysql_user,$mysql_password);
  4. if(!$connection){
  5.    die("Could not connect to the database: <br/>". mysql_error());
  6. }
  7. $db_select=mysql_select_db($mysql_database);
  8. if(!$db_select){
  9.    die("Could not select the database: <br/>".mysql_error());
  10. }
  11.  
  12. // how many rows to show per page
  13. $rowsPerPage = 10;
  14.  
  15. // by default we show first page
  16. $pageNum = 1;
  17.  
  18. // if $_GET['page'] defined, use it as page number
  19. if(isset($_GET['page']))
  20. {
  21.     $pageNum = $_GET['page'];
  22. }
  23.  
  24. // counting the offset
  25. $offset = ($pageNum - 1) * $rowsPerPage;
  26.  
  27. $query = " SELECT * FROM air_registers" .
  28.          " LIMIT $offset, $rowsPerPage";
  29. $result = mysql_query($query) or die('Error, query failed');
  30.  
  31.  
  32. while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
  33.    $type=$row["Type"];
  34.    $number=$row["Number"];
  35.    $desc=$row["Description"];
  36.    echo "<div id='type'><strong>Model Type: </strong>$type</div>";
  37.    echo "<div id='number'><strong>Model #: </strong>$number</div>";
  38.    echo "<br />";
  39.    echo "<div id='desc'><strong>Description: </strong>$desc</div>";
  40.    echo "<br />";
  41.    echo "<hr>";
  42. }
  43. // how many rows we have in database
  44. $query   = "SELECT COUNT(*) AS numrows FROM air_registers";
  45. $result  = mysql_query($query) or die('Error, query failed');
  46. $row     = mysql_fetch_array($result, MYSQL_ASSOC);
  47. $numrows = $row['numrows'];
  48.  
  49. // how many pages we have when using paging?
  50. $maxPage = ceil($numrows/$rowsPerPage);
  51.  
  52. // print the link to access each page
  53. $self = $_SERVER['PHP_SELF'];
  54. $nav  = '';
  55.  
  56. for($page = 1; $page <= $maxPage; $page++)
  57. {
  58.    if ($page == $pageNum)
  59.    {
  60.       $nav .= " $page "; // no need to create a link to current page
  61.    }
  62.    else
  63.    {
  64.       $nav .= " <a href=\"$self?page=$page\">$page</a> ";
  65.    }
  66. }
  67. // ... the previous code
  68.  
  69. // creating previous and next link
  70. // plus the link to go straight to
  71. // the first and last page
  72.  
  73. if ($pageNum > 1)
  74. {
  75.    $page  = $pageNum - 1;
  76.    $prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";
  77.  
  78.    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
  79. }
  80. else
  81. {
  82.    $prev  = '&nbsp;'; // we're on page one, don't print previous link
  83.    $first = '&nbsp;'; // nor the first page link
  84. }
  85.  
  86. if ($pageNum < $maxPage)
  87. {
  88.    $page = $pageNum + 1;
  89.    $next = " <a href=\"$self?page=$page\">[Next]</a> ";
  90.  
  91.    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
  92. }
  93. else
  94. {
  95.    $next = '&nbsp;'; // we're on the last page, don't print next link
  96.    $last = '&nbsp;'; // nor the last page link
  97. }
  98.  
  99. // print the navigation link
  100. echo $first . $prev . $nav . $next . $last;
  101.  
  102. mysql_close($connection);
  103. ?>
This works fine and displays my text information.

Here is the code for the image output to the user:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('books_login.php');
  3. include('pix.php');
  4. $connection=mysql_connect($mysql_host,$mysql_user,$mysql_password);
  5. if(!$connection){
  6.    die("Could not connect to the database: <br/>". mysql_error());
  7. }
  8. $db_select=mysql_select_db($mysql_database);
  9. if(!$db_select){
  10.    die("Could not select the database: <br/>".mysql_error());
  11. }
  12.  
  13. $strSQL = "select * from pix";
  14. $rsPix = mysql_query($strSQL);
  15. $numRows = mysql_numrows($rsPix);
  16. $i = 0;
  17.  
  18. while($i < $numRows){
  19. ?>
  20. <img src="pix.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
  21. <?php
  22. $i++;
  23. }
  24. ?>
  25.  
  26.  
And the code above refers to pix.php:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. include('books_login.php');
  3. $connection=mysql_connect($mysql_host,$mysql_user,$mysql_password);
  4. if(!$connection){
  5.    die("Could not connect to the database: <br/>". mysql_error());
  6. }
  7. $db_select=mysql_select_db($mysql_database);
  8. if(!$db_select){
  9.    die("Could not select the database: <br/>".mysql_error());
  10. }
  11. if (IsSet($_GET['pixID'])){
  12. $gotten = @mysql_query("select imgdata from pix where pixID = ".$_GET['pixID']);
  13. header("Content-type: image/jpeg");
  14. while ($row = mysql_fetch_array($gotten,MYSQL_ASSOC))
  15. {
  16. print $row['imgdata'];
  17.  
  18. }
  19. mysql_free_result($gotten);
  20. }
  21. ?>
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.
Feb 8 '09 #1
8 2297
tharden3
916 Contributor
You know, I think I almost have this figured out. I'll post new code when I solve the problem.
Feb 8 '09 #2
Markus
6,050 Recognized Expert Expert
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.
Feb 8 '09 #3
tharden3
916 Contributor
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):
Expand|Select|Wrap|Line Numbers
  1. $query = " SELECT * FROM air_registers" .
  2.          " LIMIT $offset, $rowsPerPage";
  3. $result = mysql_query($query) or die('Error, query failed');
  4.  
  5.  
  6. while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
  7.    $thumb=$row["Thumbnail"];
  8.    $type=$row["Type"];
  9.    $number=$row["Number"];
  10.    $desc=$row["Description"];
  11.    $i = 0;
  12.    echo "<div id='type'><strong>Model Type: </strong>$type</div>";
  13.    echo "<div id='number'><strong>Model #: </strong>$number</div>";
  14.    echo "<br />";
  15.  
  16.    echo '<img src="pix.php?pixID=<?php echo mysql_result($result,$i,"pixID"); ?>"/>';
  17.  
  18.    echo "<br />";
  19.    echo "<div id='desc'><strong>Description: </strong>$desc</div>";
  20.    echo "<br />";
  21.    echo "<hr>";
  22.    $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).
Feb 8 '09 #4
tharden3
916 Contributor
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:
Expand|Select|Wrap|Line Numbers
  1. 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?
Feb 11 '09 #5
Markus
6,050 Recognized Expert Expert
@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.
Feb 11 '09 #6
tharden3
916 Contributor
@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 ;)
Feb 11 '09 #7
Markus
6,050 Recognized Expert Expert
@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.
Feb 11 '09 #8
tharden3
916 Contributor
@Markus
I'll try this out and post my results.
Feb 11 '09 #9

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

Similar topics

15
425
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 it tried to link, I got the attached warnings and then an error. Any ideas why the linker wouldn't see the objects in the library? They look like pretty long names, so maybe there is some type of symbol length or mangling issue going on? The...
3
4041
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 field that links to the ImagePath field. But it does not display in the form. I go in and delete the image field and add it back in and link it to the "blank.jpg" file (its a dummy jpg that says "Not Avail"). Then I make sure it is linked and not...
1
4021
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 live databases on the network. Is there a way, via code, when I get back in-house from being on the road to click a button, and select the backends I want to link to? I would want to delete all the current links and link to the "live"
11
4544
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 database,just help in getting me pointed in the right direction. I have a database with 8 tables, which from what I have read, cannot be linked on a single form, and be updatable. I have created a query which includes all 8 tables, and then...
5
4810
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 12 records in it. I have been reading about linking images into the database and i would like to use the method linking via code this way the database will be as small as possible.
1
2341
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. THE Database used is MySQL "Support" on a Table Called "profiles": The problem is how do I get this piece of codes to link to a details page called "PATRONS_DETAILS.PHP" and display information about one particular database detail. With ID...
1
1329
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 page and i click countryname then it shows country table and then if i entered i want to go another page for result so my codings are in one form design is in one form.In submit form i am using one image.I gave link in image button but its not...
4
8075
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
3
4441
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 when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
0
9906
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11051
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10774
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7929
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5757
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.