hola tengo una duda. y no se si la puse en el lugar correcto ya qe tiene qe ver con php y javascript
yo tengo una base de datos y por ahora recojo los datos y los guardo en un array. hasta aca todo bien pero yo me pregunto. habria alguna mejora en obtener los datos con javascript o con php
por ejemplo con php hago algo asi:
Código PHP:
Ver original<?php
require 'settings.php';
$user = new user(1);
$limitNews = 20;
$news = $user->getNewsArray($limitNews);
$i = 0;
while($i <= $limitNews) {
if( empty($news[$i]) ) break; echo "<img src='{$friend[$i]['photo']}' style='width:30px; margin-right:4px' border='0'/>\n<a href='profile/{$news[$i]['username']}'>{$news[$i]['name']} {$news[$i]['surname']} </a><br>\n<div style='margin-left:10px;' id='{$news[$i]['updateID']}'>\n" . getRitchText($news[$i]['update']) . "<div style='font-size:12px;color:grey;'>" . timestamp($news[$i]['time']) . "</div>\n</div><hr>";
++$i;
}
?>
la funcion getNewsArray() me devuelve un array con los resultados y con un while los recorro y los muestro en pantalla.
pero si por ejemplo tengo un archivo qe me muestra los resultados en formato json y con jquery los muestro . por ejemplo:
Código HTML:
Ver original<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript"> var list;
jQuery(function($) {
$.getJSON('getLatestNews.php', function(updates) {
$.each(updates, function(k, item) {
if(item.error){
list += 'error al mostrar';
return false;
}
else
{
list += "
<img src='" + item.photo + "' style='width:30px; margin-right:4px' border='0'/>\n
<a href='profile/" + item.username + "'>" + item.name + " " + item.surname + "
</a><br>\n
<div style='margin-left:10px;' id='" + item.updateID + "'>\n" + item.update + "
<div style='font-size:12px;color:grey;'>" + item.time + "
</div>\n
</div><hr>";
}
});
$("#resultados").html(list);
});
});
ahora me pregunto . tengo algun beneficio en alguna de las dos formas.. eh notado que con javascript carga mas rapido.. puede ser?
desde ya . gracias!