Html grid very slow

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Html grid very slow

Post 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
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Html grid very slow

Post 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.
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Html grid very slow

Post 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.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Html grid very slow

Post 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?
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Html grid very slow

Post 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.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Html grid very slow

Post 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?
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Html grid very slow

Post by mariolopes »

Please look at
http://mariolopes.com/estagios/montealunosweb.php
Why is that so slow?
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Html grid very slow

Post by aravona »

By so slow do you mean the 4-6 seconds it takes to load?
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Html grid very slow

Post 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.
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: Html grid very slow

Post 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 :)
Post Reply