Cutting amount of work and loading time?

Thread Solved

Join Date: Apr 2008
Posts: 39
Reputation: Borderline is an unknown quantity at this point 
Solved Threads: 1
Borderline Borderline is offline Offline
Light Poster

Cutting amount of work and loading time?

 
0
  #1
May 16th, 2008
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: Cutting amount of work and loading time?

 
1
  #2
May 17th, 2008
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.

  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'")
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 39
Reputation: Borderline is an unknown quantity at this point 
Solved Threads: 1
Borderline Borderline is offline Offline
Light Poster

Re: Cutting amount of work and loading time?

 
0
  #3
May 17th, 2008
Thanks, glad to know it is possible, can save a lot of time.

  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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: Cutting amount of work and loading time?

 
0
  #4
May 17th, 2008
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


  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>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC