Jump to content

how to speed this up


cmb

Recommended Posts

I have this php page that based on what the user chooses shows them the appropriate photo galleria and i was wondering if their was any way i could speed this up this is the php code for selecting the galleria and I'm not showing the javascript that does the slide show because it s the galleriffic jquery plugin

<div id="Info">
	<div id="page">
		<div id="container">
            	<?php
				$g = mysql_real_escape_string($_GET['g']);
				$query = "SELECT * FROM pinkpanther_games WHERE Gallery_no = '$g'";
				$results = mysql_query($query) or die("Query failed ($_query) - " . mysql_error());
				$row = mysql_fetch_assoc($results);
				echo "<h1>" . $row['Day_Played'] . " vs " . $row['Opponent'] . "</h1>";
			?>
			<!-- Start Advanced Gallery Html Containers -->
			<div id="gallery" class="content">
				<div id="controls" class="controls"></div>
				<div class="slideshow-container">
					<div id="loading" class="loader"></div>
					<div id="slideshow" class="slideshow"></div>
				</div>
				<div id="caption" class="caption-container"></div>
			</div>
			<div id="thumbs" class="navigation">
				<ul class="thumbs noscript">
					<?php
						$x = $row['no_Pics'];
						$y = 1;
						$year = $row['Year_Played'];
						$day = $row['Day_Played'];
						$scheck = $row['Sessions'];
						if ($scheck == 1){
							$sessions = "Session1";
						}else{
							$sessions = "Session2";
						}
						if ($x == 0){
							echo "<li> <a  class='thumb' href='../images/nopics.jpg' title=''><img src='../images/nopicsthumb.jpg ' /></a></li>";	
						}else if ($x == 10000){
							echo "<li> <a  class='thumb' href='../images/coming.jpg' title=''><img src='../images/comingthumb.jpg ' /></a></li>";
						}else{
							while ($y <= $x){
								echo "<li> <a  class='thumb' href='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/" . $y . ".jpg' title=''><img src='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/thumbs/" . $y . ".jpg ' /></a><div class='caption'><div	class='download'><a href='../images/Sections/pinkpanthers/" . $year . "/" . $sessions . "/" . $day . "/big/" . $y . ".jpg ' target='_blank' />Download</a></div></div></li>";
								$y ++  ;	
							}
						}
					?>
				</ul>
			</div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div id="footer"></div>

 

Link to comment
Share on other sites

What makes you think that there is a performance problem with that code? more than likely the problem is a bandwidth issue - especially fi you are using very large images or a problem with the javascript.

 

But, since you ask, here are some things you can do - but most likely these will only provide marginal performance benefits which you won't even see.

 

1. List out the fields in your SELECT query instead of using '*'. Selecting all the fields when you don't need them is a waste of resources.

2. I don't know if your query is returning only one record or multiple, but you are only using the first record. So, if you are getting more than one record and only using the first, then limit your query to only one using 'LIMIT'

3. Don't assign a value from the query result to another variable only to use that variable once. Just use the value from the fetched record.

4. Your if/else statement to determine the 'sessions" text is only needed in the last else statement for the no pics value. So, put that code within the last else statement so it isn't executed unnecessarily.

5. Not sure if this would help, but it would make the code cleaner. I see you are using three variables in the same configuration multiple times in the while loop. I would assign them to a single variable and use that in the output.

 

<?php
    $g = mysql_real_escape_string($_GET['g']);
    $query = "SELECT Day_Played, Opponent, no_Pics, Year_Played, Day_Played, Sessions
              FROM pinkpanther_games
              WHERE Gallery_no = '$g'
              LIMIT 1";
    $results = mysql_query($query) or die("Query failed ($_query) - " . mysql_error());
    $row = mysql_fetch_assoc($results);
    $title =  "<h1>{$row['Day_Played']} vs {$row['Opponent']}</h1>";
    $links = '';
    
    if ($row['no_Pics'] == 0)
    {
        $links .= "<li> <a  class='thumb' href='../images/nopics.jpg' title=''><img src='../images/nopicsthumb.jpg ' /></a></li>";	
    }
    else if ($row['no_Pics'] == 10000)
    {
        $links .= "<li> <a  class='thumb' href='../images/coming.jpg' title=''><img src='../images/comingthumb.jpg ' /></a></li>";
    }
    else
    {
        if ($row['Sessions'] == 1)
        {
            $sessions = "Session1";
        }
        else
        {
            $sessions = "Session2";
        }
     
        $y = 1;
        while ($y <= $row['no_Pics'])
        {
            $rootPath = "{$row['Year_Played']}/{$sessions}/{$row['Day_Played']}";
            $links .= "<li> <a class='thumb' href='../images/Sections/pinkpanthers/{$rootPath}/{$y}.jpg' title=''><img src='../images/Sections/pinkpanthers/{$rootPath}/thumbs/{$y}.jpg ' /></a><div class='caption'><div	class='download'><a href='../images/Sections/pinkpanthers/{$rootPath}/big/{$y}.jpg ' target='_blank' />Download</a></div></div></li>";
            $y ++;
        }
    }

?>

<div id="Info">
    <div id="page">
        <div id="container">
        <?php echo $title; ?>
        <!-- Start Advanced Gallery Html Containers -->
            <div id="gallery" class="content">
                <div id="controls" class="controls"></div>
                <div class="slideshow-container">
                    <div id="loading" class="loader"></div>
                    <div id="slideshow" class="slideshow"></div>
                </div>
                <div id="caption" class="caption-container"></div>
            </div>
            <div id="thumbs" class="navigation">
                <ul class="thumbs noscript">
                <?php echo $links; ?>
                </ul>
            </div>
            <div style="clear: both;"></div>
        </div>
    </div>
    <div id="footer"></div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.