vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How many queries is too many queries?? (https://vborg.vbsupport.ru/showthread.php?t=267176)

EquinoxWorld 07-21-2011 12:59 PM

How many queries is too many queries??
 
Hello everyone, I was wondering if someone can clarify how many queries per page is too many per script. For example my php file below. This is used to get the specific image URL for each option of the form. I know I may have been able to use some sort of array but my php knowledge is very limited still but learning fast. I wonder if this is an overkill for the server although page load time is under a second, I don't know how this many queries per file might affect when used in a live large board for example. If anyone has any input or feedback or if someone knows how I can run the same script but differently and more efficient please don't hold back. Here is the said php file;

PHP Code:

<?php 
require_once('./global.php');

define('CSRF_PROTECTION'true);

       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='1'"); 
$row mysql_fetch_row($result);
       
$id1 $row[0];
       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='2'"); 
$row mysql_fetch_row($result);
       
$id2 $row[0];
       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='3'"); 
$row mysql_fetch_row($result);
       
$id3 $row[0];
       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='4'"); 
$row mysql_fetch_row($result);
       
$id4 $row[0];
       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='5'"); 
$row mysql_fetch_row($result);
       
$id5 $row[0];
       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='6'"); 
$row mysql_fetch_row($result);
       
$id6 $row[0];
       
$result $db->query_read("SELECT imgurl FROM oftw_nominations WHERE id='7'"); 
$row mysql_fetch_row($result);
       
$id7 $row[0];
      echo 
"<div id=lightboximages class=blockbody>";
      echo 
"<form cellpadding=10 border=1 action=oftw_insert_vote.php method=post>"
      echo 
"<tr>"
      echo 
"<td><center>1.<input type=radio name=votes value=1><a href=testlightbox.php?id=1 rel=Lightbox_1 id=image1><img src =".$id1." style=vertical-align:middle;padding-bottom:5px;></a></center></td>"
      echo 
"<td><center>2.<input type=radio name=votes value=2><a href=testlightbox.php?id=2 rel=Lightbox_1 id=image2><img src =".$id2." style=vertical-align:middle;padding-bottom:5px;></a></center></td>"
      echo 
"<td><center>3.<input type=radio name=votes value=3><a href=testlightbox.php?id=3 rel=Lightbox_1 id=image3><img src =".$id3." style=vertical-align:middle;padding-bottom:5px;></a></center></td>"
      echo 
"<td><center>4.<input type=radio name=votes value=4><a href=testlightbox.php?id=4 rel=Lightbox_1 id=image4><img src =".$id4." style=vertical-align:middle;padding-bottom:5px;></a></center></td>"
      echo 
"<td><center>5.<input type=radio name=votes value=5><a href=testlightbox.php?id=5 rel=Lightbox_1 id=image5><img src =".$id5." style=vertical-align:middle;padding-bottom:5px;></a></center></td>"
      echo 
"<td><center>6.<input type=radio name=votes value=6><a href=testlightbox.php?id=6 rel=Lightbox_1 id=image6><img src =".$id6." style=vertical-align:middle;padding-bottom:5px;></a></center></td>"
      echo 
"<td><center>7.<input type=radio name=votes value=7><a href=testlightbox.php?id=7 rel=Lightbox_1 id=image7><img src =".$id7." style=vertical-align:middle;padding-bottom:5px;></a></center></td>";
      echo 
"</tr>";
      echo 
"<center><input type=submit name=submitvote style=width:70px;></center>";
      echo 
"</form>";
      echo 
"</div>";
     


?>


Mooff 07-21-2011 01:53 PM

Code:

$result = $db->query_read("
                SELECT
                    imgurl
                FROM
                    oftw_nominations
                ORDER BY
                    id
                    ASC LIMIT 7
                    ");

$output = '<div id=lightboximages class=blockbody>
                <form cellpadding=10 border=1 action=oftw_insert_vote.php method=post>
                <tr>';
                foreach($result as $key => $row)
                {               
                    $output .= '<td><center>' . $key . '.<input type=radio name=votes value=' . $key . '><a href=testlightbox.php?id=' .$key. ' rel=Lightbox_1 id=image'. $key .'1><img src ='.$row.' style=vertical-align:middle;padding-bottom:5px;></a></center></td>';
                };

$output .= '</tr>
            <center><input type=submit name=submitvote style=width:70px;></center>
            </form>
            </div>';

echo "$output";

I don't know about how many querys are to many. But you can shrink them down in your code. Same goes for the echos.

sidenote: http://www.php.net/ is a great source for php functions. =)

EquinoxWorld 07-21-2011 06:05 PM

Thanks for the reply Moof, but every time I try and use your code replacing mine I can't access the site for some reason. All pages of the site go blank.... In any case I was able to shrink the echos using your method and page load time reduced by a few milliseconds :) Every little bit helps I suppose. I wonder why I am getting those blank screens though with the rest of your code.


All times are GMT. The time now is 02:17 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00994 seconds
  • Memory Usage 1,746KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete