943,717 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 738
  • PHP RSS
May 16th, 2008
0

Cutting amount of work and loading time?

Expand Post »
Hi There

I have a very simple web gallery in php and mysql. I have noticed upon creating it, that I have several fields in my database contacting the same information (to a certain extent) and I wondered whether this would eventually put a strain on my server. Would it be possible to marry two or more of the columns together in the php coding to produce the same result?

It also seems daft spending time putting the same info into the database over and over again.

My database currently looks like this: http://www.equinefocus.co.uk/sampledatabase.jpg - however, this has not yet had the main image url included, which would look like the thumb field, but without the /thumbs/ directory included.

For example:

Each photo has a reference number, which consists of:
COLOR="red"]date[/COLOR] and an image number
i.e. 2008-04-13-001

Each thumbnail consists of:
directory path + date + /thumbs/ + image number + file extension
i.e. /photos/eventing/2007-09-01/thumbs/001 .jpg

For the thumbnail, would it be possible to pull the directory path, date, image number from the database, have the file extension and /thumb/ section in the php code, and have all elements join together to form the link to the image? It would mean that some of the content is being used more than once (date appears in the url to the image and the reference number displayed underneath).

My current code to produce the image is:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. // Connects to your Database
  3. mysql_connect("*****", "*****", "*****") or die(mysql_error());
  4. mysql_select_db("*****")
  5. or die ("Unable to connect to MySQL");
  6.  
  7. $data = mysql_query("SELECT * FROM `others` WHERE date = '2008-04-27' AND ref ='2008-04-27-001'")
  8. or die ("No data available, please contact the site admin describing where you found this error message.");
  9. ?>
  10.  
  11. <table cellpadding="2" width="65%">
  12.  
  13. <?php
  14. while($info = mysql_fetch_array($data)) {
  15. ?>
  16.  
  17. <tr><td> <img src="<?php echo $info['full'];?>" border="0"</a></td></tr>
  18. <tr><td> <span class="refno">Photo Reference: <?php echo $info['ref']; ?></span></td></tr>
  19. <tr><td> <?php echo $info['info']; ?></td></tr>
  20.  
  21. </table>

Bit complex, sorry! Any assistance would be appreciated.
Last edited by Borderline; May 16th, 2008 at 6:31 pm.
Similar Threads
Reputation Points: 11
Solved Threads: 1
Light Poster
Borderline is offline Offline
49 posts
since Apr 2008
May 17th, 2008
1

Re: Cutting amount of work and loading time?

merge thumb and url into image - colunm just contains name e.g 1.jpg
your ref seems to be primary key and date. if true, get rid of ref.

PHP Syntax (Toggle Plain Text)
  1. // images
  2. $big_image='/photos/eventing/'.$info['date'].'/'.$info['image'];
  3. $thumb='/photos/eventing/'.$info['date'].'/thumbs/'.$info['image'];
  4.  
  5. // ref
  6. $ref = $info['date'].'-'.$info['primary_id'];
  7.  
  8. // mysql
  9. $data = mysql_query("SELECT * FROM `others` WHERE date = '2008-04-27' AND primaryid ='1'")
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
amigura is offline Offline
71 posts
since Jan 2008
May 17th, 2008
0

Re: Cutting amount of work and loading time?

Thanks, glad to know it is possible, can save a lot of time.

PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <head><link rel="stylesheet" type="text/css" href="http://www.equinefocus.co.uk/style/20080512.css"/></head>
  3.  
  4. <html><body>
  5.  
  6. <?php $page_title='Equine Focus';
  7. include($_SERVER['DOCUMENT_ROOT'].'/style/20080512photography.php');?>
  8.  
  9. <div id="main">
  10. <center>
  11.  
  12. <div class="pagination">
  13. <ul>
  14. <li><a href="/photos/other/2008-04-27/page01.php">Return to album</a></li>
  15. </ul>
  16. </div>
  17.  
  18. <?php
  19. // Connects to your Database
  20. mysql_connect("*****", "*****", "*****") or die(mysql_error());
  21. mysql_select_db("*****")
  22. or die ("Unable to connect to MySQL");
  23.  
  24. // images
  25. $big_image='/photos/eventing/'.$info['date'].'/'.$info['image'];
  26. $thumb='/photos/eventing/'.$info['date'].'/thumbs/'.$info['image'];
  27.  
  28. // ref
  29. $ref = $info['date'].'-'.$info['ref'];
  30.  
  31. // mysql
  32. $data = mysql_query("SELECT * FROM `eventing` WHERE date = '2008-04-13' AND ref ='080'") or die
  33. ("No data available, please contact the site admin describing where you found this error message.");
  34. ?>
  35.  
  36. <table cellpadding="2" width="65%">
  37.  
  38. <?php
  39. while($info = mysql_fetch_array($data)) {
  40. ?>
  41.  
  42. <tr><td> <img src="<?php echo $info['$big_image'];?>" border="0"</a></td></tr>
  43. <tr><td> <span class="refno">Photo Reference: <?php echo $info['$ref']; ?></span></td></tr>
  44. <tr><td> <?php echo $info['info']; ?></td></tr>
  45.  
  46. </table>
  47.  
  48.  
  49. <?php
  50. }
  51. ?>
  52. </table>
  53.  
  54.  
  55. </div></center>
  56. </html></body>

End result is: http://www.equinefocus.co.uk/test_page.php - what errors have I made calling the info from the database?
Reputation Points: 11
Solved Threads: 1
Light Poster
Borderline is offline Offline
49 posts
since Apr 2008
May 17th, 2008
0

Re: Cutting amount of work and loading time?

the $info['$big_image'] is not from db it is a set varible so it should be echo $big_image and same with $info['ref'] - echo $ref;
the image and ref should go below db query to get info also


PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <head><link rel="stylesheet" type="text/css" href="http://www.equinefocus.co.uk/style/20080512.css"/></head>
  3.  
  4. <html><body>
  5.  
  6. <?php $page_title='Equine Focus';
  7. include($_SERVER['DOCUMENT_ROOT'].'/style/20080512photography.php');?>
  8.  
  9. <div id="main">
  10. <center>
  11.  
  12. <div class="pagination">
  13. <ul>
  14. <li><a href="/photos/other/2008-04-27/page01.php">Return to album</a></li>
  15. </ul>
  16. </div>
  17.  
  18. <?php
  19. // Connects to your Database
  20. mysql_connect("*****", "*****", "*****") or die(mysql_error());
  21. mysql_select_db("*****")
  22. or die ("Unable to connect to MySQL");
  23.  
  24.  
  25.  
  26. // mysql
  27. $data = mysql_query("SELECT * FROM `eventing` WHERE date = '2008-04-13' AND ref ='080'") or die
  28. ("No data available, please contact the site admin describing where you found this error message.");
  29. ?>
  30.  
  31. <table cellpadding="2" width="65%">
  32.  
  33. <?php
  34. while($info = mysql_fetch_array($data)) {
  35. // images
  36. $big_image='/photos/eventing/'.$info['date'].'/'.$info['image'];
  37. $thumb='/photos/eventing/'.$info['date'].'/thumbs/'.$info['image'];
  38.  
  39. // ref
  40. $ref = $info['date'].'-'.$info['ref'];
  41. ?>
  42.  
  43. <tr><td> <img src="<?php echo $big_image; ?>" border="0"</a></td></tr>
  44. <tr><td> <span class="refno">Photo Reference: <?php echo $ref; ?></span></td></tr>
  45. <tr><td> <?php echo $info['info']; ?></td></tr>
  46.  
  47. </table>
  48.  
  49.  
  50. <?php
  51. }
  52. ?>
  53. </table>
  54.  
  55.  
  56. </div></center>
  57. </html></body>
Reputation Points: 11
Solved Threads: 7
Junior Poster in Training
amigura is offline Offline
71 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Updating required 2 Clicks of the same button
Next Thread in PHP Forum Timeline: creating dynamic columns and rows with data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC