Page 1 of 1

Html grid very slow

Posted: Mon Jan 25, 2010 10:41 am
by mariolopes
Hi
I present my data with a html table. I have about 200 records but the show process is very slow.
Here is my code:
echo"<table border='2'>";
echo"<tr>";
echo"<td>";echo"Apagar";echo"</td>";
echo"<td>";echo"Editar";echo"</td>";
echo"<td>";echo"Id";echo"</td>";
echo"<td>";echo "<a href='minhagrid.php?Ordem=";echo "Codigo";echo "'>Código</a>";echo "</td>";
echo"<td>";echo"Designação->";echo"</td>";
echo"<td>";echo"Preco_compra";echo"</td>";
echo"<td>";echo"Preco_venda";echo"</td>";
echo"<td>";echo"Data Compra";echo"</td>";
echo"<td>";echo"Data de Venda";echo"</td>";
echo"</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>"; echo "<a href='Apagar.php?Id=";echo $row[Id];echo "'>Apagar</a>";echo "</td>";
echo "<td>"; echo "<a href='form/form.php?Id=";echo $row[Id];echo "'>Editar</a>";echo "</td>";
echo "<td>";echo $row['Id'];echo"</td>";
echo "<td>";echo $row['Codigo'];echo"</td>";
echo "<td>";echo $row['Designacao'];echo"</td>";
echo "<td>";echo $row['Preco_compra'];echo"</td>";
echo "<td>";echo $row['Preco_venda'];echo"</td>";
echo "<td>";echo $row['Data_compra'];echo"</td>";
echo "<td>";echo $row['Data_venda'];echo"</td>";
echo"</tr>";
}
echo"</table>";

How can i improve it? Any help?
Thank you

Re: Html grid very slow

Posted: Mon Jan 25, 2010 10:49 am
by aravona
As for speeding it up not sure, but you don't need to echo everything like that. You should get the same result using:

Code: Select all

 
echo"<table border='2'><tr>";
echo"<td>Apagar</td>";
echo"<td>Editar</td>";
echo"<td>Id</td>";
echo"<td><a href='minhagrid.php?Ordem=";echo "Codigo";
echo "'>Código</a></td>";
echo"<td>Designação-></td>";
echo"<td>Preco_compra</td>";
echo"<td>Preco_venda</td>";
echo"<td>Data Compra</td>";
echo"<td>Data de Venda</td>";
echo"</tr>";
 
as you did using:

Code: Select all

echo"<table border='2'>";
echo"<tr>";
echo"<td>";echo"Apagar";echo"</td>";
echo"<td>";echo"Editar";echo"</td>";
echo"<td>";echo"Id";echo"</td>";
echo"<td>";echo "<a href='minhagrid.php?Ordem=";echo "Codigo";echo "'>Código</a>";echo "</td>";
echo"<td>";echo"Designação->";echo"</td>";
echo"<td>";echo"Preco_compra";echo"</td>";
echo"<td>";echo"Preco_venda";echo"</td>";
echo"<td>";echo"Data Compra";echo"</td>";
echo"<td>";echo"Data de Venda";echo"</td>";
echo"</tr>";
In theory it would speed it up slightly as the computer is reading less. But not significantly, since you're pulling so much data.

Re: Html grid very slow

Posted: Mon Jan 25, 2010 11:01 am
by mariolopes
Hi
I think the best option is to paging the results. Unfortunately i don't know how can i do it but i have to study that option, otherwhise the result is very slow.

Re: Html grid very slow

Posted: Mon Jan 25, 2010 12:30 pm
by JNettles
There a number of factors that could be at play here. I doubt your echo has anything to do with it - milliseconds at most. What does your SELECT statement look like? How many joins?

Re: Html grid very slow

Posted: Tue Jan 26, 2010 5:00 am
by mariolopes
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi JNettles
I tried paging my grid but i don't win much more time. My sql has no joins there it is all the code:

Code: Select all

<?php
$mysql_id = mysql_connect('localhost', "curso", "123");
mysql_select_db('mariolopes',$mysql_id);
$pag = $_GET['pag'];
if (!isset($pag)){
   $pag = 1;
}
$resultados = 10;
$query="select * from negocios ";
$result=mysql_query($query);
$resultados_total = mysql_num_rows($result);
$paginas=ceil($resultados_total/$resultados);
$inicio=($pag-1)*$resultados;
if(!isset($_GET[Ordem])){
$query="select * from negocios order by id DESC LIMIT $inicio,$resultados ";//order by id DESC
$result=mysql_query($query);    
}
if($_GET[Ordem]="Codigo"){
$query="select * from negocios order by Codigo LIMIT $inicio,$resultados ";//order by Codigo
$result=mysql_query($query);
}
 
echo"<a href='insereprodutos/forminserir.html'>";echo"Inserir Produto";echo"</a>";
echo"<table border='2'>";
echo"<tr>";
echo"<td>Apagar</td>";
echo"<td>Editar</td>";
echo"<td>Id</td>";
echo"<td>";echo "<a href='minhagrid.php?Ordem=";echo "Codigo";echo "'>Código</a>";echo "</td>";
echo"<td>Designação-></td>";
echo"<td>Preco_compra</td>";
echo"<td>Preco_venda</td>";
echo"<td>Data Compra</td>";
echo"<td>Data de Venda</td>";
echo"</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>"; echo "<a href='Apagar.php?Id=";echo $row[Id];echo "'>Apagar</a>";echo "</td>";
echo "<td>"; echo "<a href='form/form.php?Id=";echo $row[Id];echo "'>Editar</a>";echo "</td>";
echo "<td>";echo $row['Id'];echo"</td>";
echo "<td>";echo $row['Codigo'];echo"</td>";
echo "<td>";echo $row['Designacao'];echo"</td>";
echo "<td>";echo $row['Preco_compra'];echo"</td>";
echo "<td>";echo $row['Preco_venda'];echo"</td>";
echo "<td>";echo $row['Data_compra'];echo"</td>";
echo "<td>";echo $row['Data_venda'];echo"</td>";
echo"</tr>";
}
echo"</table>";
echo "Pág: ";
for($i=1;$i<=$paginas;$i++){
    echo "<a href='minhagrid.php?pag=";echo$i;echo "'>$i</a>";echo "</td>";
}
?>

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Html grid very slow

Posted: Tue Jan 26, 2010 9:54 am
by JNettles
Simply looking at your SQL I can't see any real issues other than that sometimes using ORDER BY LIMIT can be a bit of a tax but shouldn't be anything really noticeable. Exactly how long is the page taking to fully render?

Re: Html grid very slow

Posted: Tue Feb 02, 2010 6:36 am
by mariolopes
Please look at
http://mariolopes.com/estagios/montealunosweb.php
Why is that so slow?

Re: Html grid very slow

Posted: Tue Feb 02, 2010 6:39 am
by aravona
By so slow do you mean the 4-6 seconds it takes to load?

Re: Html grid very slow

Posted: Tue Feb 02, 2010 8:21 am
by JNettles
I don't really notice any speed issues honestly - page loaded in under 2 seconds for me. If its taking longer, it could be a hardware issue - check with your web host.

Re: Html grid very slow

Posted: Tue Feb 02, 2010 8:31 am
by aravona
JNettles wrote:I don't really notice any speed issues honestly - page loaded in under 2 seconds for me. If its taking longer, it could be a hardware issue - check with your web host.
Quite likely, I think it loaded slow for me due to video uploads going on constantly on our net connection, still varied and did load faster when the office was quieter. Still anywhere between 3-8 seconds isnt that slow, its just slightly annoying :)