Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 16th, 2004, 01:10 PM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trouble getting right data out of a table

  I have 2 tables: 1 for biography info (tbl_photographers). The other for photo info (tbl_photographs) that contains a photoID column.

  Each contains a photographerID column.

Three pages are viewed by a visitor:

  1) a photographer's name in a list is linked to page 2.
  2) this page shows numerous images by the singled-out photographer. Each of the images (photoID) is linked to page 3.
  3) the selected image from page 2 becomes enlarged and supported by descriptive material.

  Everything works fine except page 3. The name of the photographer shows up as the default record "1" instead of the selected photographer whose ID may be "6". The selected image is OK as is the descriptive material.


  I have the feeling that there's just one or two simple corrections/additions to the code in the final segment of 2.

  Thanks for any help.

Don
 
Old August 25th, 2004, 12:10 AM
Authorized User
 
Join Date: Aug 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sinapra Send a message via MSN to sinapra Send a message via Yahoo to sinapra
Default

I hope i got it right. Let me explain what i understood first, The user with Id 6 clicks for the description and it takes him to page2. Then he gets the images in page2 and on clicking the images, it should take him to page3 with the image enlarged. right!!!

We can have two ways to do it :
Since Id is taking to default 1 and showing its images, you can pass the Id values either in hidden values or using sessions and retrieve the images as per the selected Id. You can print the Id to check if it has come to the page2 from where the job becomes easy. I hope I am clear in describing.

Regards


sinapra
 
Old August 25th, 2004, 09:26 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You have correctly perceived the problem.

The object is to show the photographer's name along with his/her photograph. I am able to pass the photoID from page 2 to page 3 where upon the correct image is displayed. I have attempted to pass the photographerID as well but page 3 does not recognize it and so uses the default ID of 1.

Your suggestion of using a hidden value sounds good and I'll attempt that. I am not familiar with using the sessions technique. I'll look into that.

At this point I am working strictly at the localhost level and do not want to upload anything until all works properly so there's no site yet where the problem can be seen.

Thanks!

TwoNames

 
Old August 25th, 2004, 10:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If each photo's record has a photographerID column, couldn't you use that? Are you trying to use that, and all you're getting is ID 1? If so, have you checked to see what values your photographerID column actually holds for each photo?

Maybe a if we could have look at some of your code, it would help.
Dan
 
Old August 25th, 2004, 11:56 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's code from page 3.

<?php

//Setting up for specific photographer's selected image & descriptive data.

$colname_rs_photographsEnlarged = "1";

if (isset($_GET['photoID'])) {
  $colname_rs_photographsEnlarged = (get_magic_quotes_gpc()) ? $_GET['photoID'] : addslashes($_GET['photoID']);
}

mysql_select_db($database_phototest, $phototest);

$query_rs_photographsEnlarged = sprintf("SELECT * FROM tbl_photographs WHERE photoID = %s", $colname_rs_photographsEnlarged);

$rs_photographsEnlarged = mysql_query($query_rs_photographsEnlarged, $phototest) or die(mysql_error());

$row_rs_photographsEnlarged = mysql_fetch_assoc($rs_photographsEnlarged);

$totalRows_rs_photographsEnlarged = mysql_num_rows($rs_photographsEnlarged);

?>

<?php

//The following is suppose to bring in the photographer's ID that will allow this file to show the photographer's name.
//It doesn't. It uses "1" as default and Hine's name appears every time. However, if the previous GET above is changed from photoID
//to photographerID, the name is OK, but the image is one of Hine's. There must be some way to get both correct from the photographs_detail file.

$colname_rs_photographer = "1";

if (isset($_GET['photographerID'])) {
  $colname_rs_photographer = (get_magic_quotes_gpc()) ? $_GET['photographerID'] : addslashes($_GET['photographerID']);

}

mysql_select_db($database_phototest, $phototest);

$query_rs_photographer = sprintf("SELECT photographerID, photographerName FROM tbl_photographers WHERE photographerID = %s",
$colname_rs_photographer);

$rs_photographer = mysql_query($query_rs_photographer, $phototest) or die(mysql_error());

$row_rs_photographer = mysql_fetch_assoc($rs_photographer);

$totalRows_rs_photographer = mysql_num_rows($rs_photographer);
?>

Here's the code for echoing the data:

 <p><img src="<?php
    // Displays photograph and details of same. Should be enlarged, single image linked from photographsDetail.
     echo $row_rs_photographsEnlarged['photoURL2']; ?>" alt="photograph" /></p>
    <p> <?php echo $row_rs_photographer['photographerName']; ?><br />
        <?php echo $row_rs_photographsEnlarged['title'],", "; ?>
        <?php echo $row_rs_photographsEnlarged['date'],", "; ?>
        <?php echo $row_rs_photographsEnlarged['location']; ?><br />
        <?php echo $row_rs_photographsEnlarged['description']; ?><br />
        <?php echo $row_rs_photographsEnlarged['media']; ?> </p>

  I checked the data base and the photograperID in both tables are proper, the ID numbers match the photographer.

  Page two works well as the photographer's name and all related photos appear fine. It's just that the photographerID does not seem to get passed to page 3.

Thanks for any help.

TwoNames

 
Old August 26th, 2004, 01:19 AM
Authorized User
 
Join Date: Aug 2004
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sinapra Send a message via MSN to sinapra Send a message via Yahoo to sinapra
Default

Hi
Can you tell me the significance of the first line code where where you have hardcoded $colname_rs_photographsEnlarged to '1'. If thats the default size that the user is allowed to see, thats ok.
I can suggest you another way where you can show some results in page 2 itself, you can query and display the images of user1 in page 2 in colomns which will have links. As he clicks on any particular image, it opens a pop-up window and the image displayed in full size. This can make the job easier. You can at the same time store all the images in array and display 'First', 'Next', 'Last' in third page passed from the second page. I may not be able to put the code right now, if you want, I can get the code too.

Regards

sinapra
 
Old August 26th, 2004, 07:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is what I was meaning:

If I understood your database structure correctly, the $rs_photographsEnlarged resultset will contain an entry for 'photographerID', which could be retrieved as $row_rs_photographsEnlarged['photographerID']....So you want something like:

$colname_rs_photographer = $row_rs_photographsEnlarged['photographerID'];

$query_rs_photographer = sprintf("SELECT photographerID, photographerName FROM tbl_photographers WHERE photographerID = %s",
$colname_rs_photographer);

Is that any help?
Dan
 
Old August 26th, 2004, 09:47 AM
Authorized User
 
Join Date: Aug 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dan and Sinapra,

  THANKS!! Mucho!!

Dan's code worked perfectly. Changing the "1" was what was needed. It always seems when I spend hours/days looking, it's really right in front of me, but I can't see it.

This is my first attempt at converting old HTML sites to databased with PHP and MySQL. It's worth the effort and without guidance and support from folks such as yourselves, . . . well, I just can't say thanks enough. It's hard to locate anyone working with PHP/MySQL around here in Houston.

Regards,

TwoNames






Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with formatting text in table cells! Sickopuppie HTML Code Clinic 5 June 21st, 2006 03:17 AM
Trouble display complete string in table BrendonMelville ASP.NET 1.0 and 1.1 Basics 4 February 27th, 2006 10:58 AM
Table trouble knalle HTML Code Clinic 5 November 10th, 2004 07:04 PM
Trouble with connecting two table with relationshi tycoon Dreamweaver (all versions) 1 December 26th, 2003 07:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.