Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Speed when pulling data from database
Old 05-17-2009, 11:33 PM Speed when pulling data from database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Hi,
I have created an offline system which normally runs very quickly.
But when it comes to displaying more and more information in a table it starts slowing down.

Eg. Only 1 item gets displayed. People can click + or - images and it adds an addition # of item 1. (still only 1 record showing)

As people add more items, (item 2, 3, 4, 5) it now shows 5 items in the table. When people click + or - images it now slows down. It seems sluggish.

When people click + and - it changes database entry and then redirects them. When it redraws the new page it responds slower (people cant spam click + and - anymore)
Is there anyway to display the items in the table faster? or to speed up the page creation?

I think I know one way I can change it but I'm not sure about the code. At the moment its split between 2 functions. Pulling data from 2 database tables.

This is how I pull data from the database. How do I pull from multi tables in same SELECT?
PHP Code:
    $sql_text "SELECT id, minsize, maxsize FROM ".$this->TABLES[$type]." WHERE id = '$unitid' ORDER BY id"
By making this 1 function would it speed everything up?
__________________
Websites Created;
warscope.com
ratepayers.org.nz

Last edited by lothop; 05-17-2009 at 11:34 PM..
lothop is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-18-2009, 02:49 AM Re: Speed when pulling data from database
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Databases are really fast, unless your pulling hundreds or thousands of records, changing one query will not make much differnce. Or perhaps your storing the images as blobs in the database? I recon that would take longer time.

I dont really understand what the + and - does?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-18-2009, 07:59 AM Re: Speed when pulling data from database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Maybe its firefox not able to respond quickly.

The + and - are just images the user clicks on to add or subtract an items amount.
__________________
Websites Created;
warscope.com
ratepayers.org.nz
lothop is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 01:08 PM Re: Speed when pulling data from database
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
Frankly there's no "one size fixes all" approach to this. You could have literally thousands of things slowing your page load down.

Your multiple table problem is pretty easy to solve though. You need to use the SQL keyword "JOIN". Here's a bogus example.

Code:
SELECT parent_id, parent_name, child_id, child_name FROM parent JOIN child ON parent.parent_id = child.parent_id
This assumes that there's a match between the parent and child tables on those two columns, but this should give you a general idea of how it works. For more information, you can check out this w3schools page.

http://www.w3schools.com/Sql/sql_join.asp
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Old 05-18-2009, 01:55 PM Re: Speed when pulling data from database
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
One thing that can help is to cache the query results
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 03:36 PM Re: Speed when pulling data from database
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Another things that come to my mind is the structure of the HTML you use.
If you use tables, firefox will wait to have a certain amount of rows before displaying the table, except if the </table> tag is found.
IE, as I remember, starts to draw the table immediately.

On pages with a lot of html, it can lead to the impression that frefox is slow, when it's just a matter of display.

But on a page with 2 or 3 rows, it should not bother the browser the least.
What could happen then is that there is javascript updating the UI as far as the table is constructed.
Depending of the processing made, this can bring firefox to a 5/6 seconds freeze.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-18-2009, 04:50 PM Re: Speed when pulling data from database
Novice Talker

Posts: 13
Trades: 0
Maybe you should post your php code. Two nested SELECTs with only a couple of rows in the resultset cannot be a performance problem. And your select statements seem to be quite simple.
__________________
My ITwiw profile:
Please login or register to view this content. Registration is FREE

You can use your
Please login or register to view this content. Registration is FREE
profile as a virtual name card anywhere on the web.
itwiw is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 07:17 PM Re: Speed when pulling data from database
lothop's Avatar
Ultra Talker

Posts: 303
Trades: 0
Thanks for your help guys. Here is my PHP

PHP Code:
<?php echo $functions->getCurrentArmy($_GET['armymodel']); ?>
PHP Code:
<?php
require('system/header.inc.php');
if (
$functions->*functionname*($_GET['armymodel'], $_GET['option'])) {
      
header("Location: index.php?type=".$_GET['type']."&unit=".$_GET['unit']."&armymodel=".$_GET['armymodel']."&opt=".$_GET['opt']."");
        } else {
      
header("Location: index.php?p=Error&referer=$referer&code=".$functions->ERROR);
        }
?>
PHP Code:
function getCurrentArmy($armymodel) {
    
$sql_text "SELECT id, unitid, minsize, maxsize, currentsize, points, type, totalpoints, standard, musician, champ,  standardcost, musiciancost, champcost FROM ".$this->TABLES['currentarmy']." ORDER BY id";
    
$data $this->sql->Select($sql_text);
    
$i=0;
    
$len count($data);
if (
$len 1) {
    
$str .='
         '
;  
    } else {
for (
$i=0$i$len$i++) {
$str .='
'
.$this->GetUnit($data[$i]['id'], $data[$i]['unitid'], $data[$i]['minsize'], $data[$i]['maxsize'], $data[$i]['currentsize'], $data[$i]['points'], $data[$i]['type'], $data[$i]['totalpoints'], $data[$i]['standard'], $data[$i]['musician'], $data[$i]['champ'], $armymodel).
'
;
}}
    return 
$str;
  }

function 
GetUnit($id$unitid$minsize$maxsize$currentsize$points$type$totalpoints$standard$musician$champ$armymodel) {
    
$sql_text "SELECT id,    name, M, WS, BS, S, T, W, I, A, LD, weapons, armour, armoursave, unitstrength, valourofages, speedofasuryan, martialprowess, minsize, maxsize, points, champcost FROM ".$this->TABLES[$type]." WHERE id = '$unitid' ORDER BY id";
    
$data $this->sql->Select($sql_text);
    
$i=0;
    
$len count($data);
if (
$len 1) {
    
$str .='
          <tr>
          <td>There was a problem and couldnt pull any core units from database.</td>
        </tr>
         '
;  
    } else {
for (
$i=0$i$len$i++) {

if (
$armymodel == $id) {
$class1 'unitselected';
$class2 'unitstatsselected';
}else{
$class1 'unitlinks';
$class2 'tabletop';
}


$str .='<tr>
          <td class="tabletopfirst"><a href="index.php?type='
.$_GET['type'].'&unit='.$_GET['unit'].'&armymodel='.$id.'&opt='.$unitid.'" class="'.$class1.'">'.$data[$i]['name'].'</a></td>';
if (
$champ 1) { $adjustedsize $currentsize 1;}else{$adjustedsize $currentsize;}
      
$str .='  <td class="'.$class2.'"><div align="center">'.$adjustedsize.'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['M'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['WS'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['BS'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['S'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['T'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['W'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['I'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['A'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['LD'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['armoursave'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['wardsave'].'</div></td>
          <td class="'
.$class2.'"><div align="center">'.$data[$i]['unitstrength'].'</div></td>
          <td class="'
.$class2.'"><div align="left">';
        
if (
$standard 1) {$str .='Std &nbsp;&nbsp;';}
if (
$musician 1) {$str .='Mus ';}
          
$str .=' </div></td>
          <td class="'
.$class2.'"><div align="center">'.$totalpoints.'</div></td>
        </tr>'
;
if (
$champ 1) {
$str .='
          <td class="firstgreytext"><div align="left">˜Champ Name</div></td>
          <td class="greytext"><div align="center">1</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['M'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['WS'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['BS'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['S'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['T'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['W'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['I'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['A'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['LD'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['armoursave'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['wardsave'].'</div></td>
          <td class="greytext"><div align="center">'
.$data[$i]['unitstrength'].'</div></td>
          <td class="greytext">&nbsp;</div></td>
          <td class="greytext"><div align="center">['
.$data[$i]['champcost'].']</div></td>
        </tr>'
;}
}}
    return 
$str;
  } 
Each time it loads the index page. It has 5 function pulls.
__________________
Websites Created;
warscope.com
ratepayers.org.nz

Last edited by lothop; 05-18-2009 at 07:19 PM..
lothop is offline
Reply With Quote
View Public Profile
 
Old 05-19-2009, 12:32 PM Re: Speed when pulling data from database
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
In that case, I'd recommend running your queries simultaneously using threads.
Then, just assemble your page afterward using the resultant data.

5 could take the time of one
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 05-20-2009, 06:03 PM Re: Speed when pulling data from database
Experienced Talker

Posts: 31
Trades: 0
Quote:
Originally Posted by anderswc View Post
Frankly there's no "one size fixes all" approach to this. You could have literally thousands of things slowing your page load down.
Couldn't agree more.

Quote:
Originally Posted by anderswc View Post
Your multiple table problem is pretty easy to solve though. You need to use the SQL keyword "JOIN". Here's a bogus example.
JOINs will work but they are slow.
GrantMePeace is offline
Reply With Quote
View Public Profile
 
Old 05-20-2009, 06:19 PM Re: Speed when pulling data from database
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
JOINs will work but they are slow.
No, they are slow only if you don't use them correctly.
In fact, you need to use joins, if you don't want to use an normalized db structure.

It's what an OLAP cube is doing.
The dimensions are nothing less than aggregated datas pulled out from joined table to normalize them in one big table.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-21-2009, 08:54 AM Re: Speed when pulling data from database
Junior Talker

Posts: 3
Name: SIMBU
Trades: 0
Database views in Microsoft SQL Server 2000 provide a flexible and efficient way to display data. Using a view allows us to pull data from many tables, incorporate sophisticated Transact-SQL and user defined functions, grab the Top N or Bottom N records, and even pull records from partitioned tables and tables located on disparate servers. Iron Speed Designer provides developers with some great properties to facilitate working with views. Virtual primary keys and virtual foreign keys, the ability to select the column you want displayed in place of a foreign key value...these all greatly enable the use of views in an Iron Speed Designer application.
Recently I found myself needing to display users’ expense data in an application. By using a view I could easily bring in other supporting data and give the user a richer and more meaningful data viewing experience than would be possible by pulling data from the Expenses table alone.



================================================== ====
famous vegan
permanente make up
abinaya is offline
Reply With Quote
View Public Profile
 
Old 05-21-2009, 01:18 PM Re: Speed when pulling data from database
Junior Talker

Posts: 2
Name: Musn
Trades: 0
I have created an offline system which normally runs very quickly.
But when it comes to displaying more and more information in a table it starts slowing down.

Harry
__________________

Please login or register to view this content. Registration is FREE
guccihand is offline
Reply With Quote
View Public Profile
 
Old 05-22-2009, 09:36 AM Re: Speed when pulling data from database
markAtRitetek's Avatar
Experienced Talker

Posts: 32
Name: Mark Hudson
Location: Atlanta, GA
Trades: 0
Is there a maximum to how many rows you are pulling from the table? If there is, it's always a good practice to put a LIMIT statement on the end of your query so that when the limit is reached MySQL does not search for more rows matching your query. For example if you KNOW that only one row will be returned, put a "LIMIT 1" on the end of the query to tell MySQL to stop after it finds one row, because while you may know that you are only looking for one row MySQL does not and will look through the entire table if you do not explicitly set a limit.

This most likely would not slow down your result too much since you're not pulling that much information from the table, and it would only make a difference with hundreds and thousands of rows, but it's always good to put a limit there to speed things along.
__________________
Mark Hudson
Ritetek Design

Please login or register to view this content. Registration is FREE
markAtRitetek is offline
Reply With Quote
View Public Profile Visit markAtRitetek's homepage!
 
Reply     « Reply to Speed when pulling data from database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47450 seconds with 12 queries