Ver Mensaje Individual
  #12 (permalink)  
Antiguo 13/01/2014, 14:08
Avatar de wolfmoon
wolfmoon
 
Fecha de Ingreso: octubre-2007
Mensajes: 189
Antigüedad: 16 años, 6 meses
Puntos: 2
Respuesta: Aplicacion php y json

Código PHP:
Ver original
  1. //** FUNCION PARA LISTAR PROYECTOS POR ID  ***************************************************************/
  2.     public function getProjectId($id){
  3.        
  4.         $sql = "select "
  5.             ."p.project_id, "
  6.             ."p.project_titulo, "
  7.             ."p.project_detalle, "
  8.             ."p.project_cliente, "
  9.             ."p.project_bg, "
  10.             ."p.project_tags, "
  11.             ."p.project_fecha, "
  12.             ."p.project_hash, "
  13.             ."i.id_imagenes, "
  14.             ."i.examples, "
  15.             ."i.example_link, "
  16.             ."i.example_type, "
  17.             ."i.project_id "
  18.             ."from "
  19.             ."portafolio as p, imagenes_project as i "
  20.             ."where "
  21.             ."p.project_id = '$id' "
  22.             ."and "
  23.             ."p.project_id = i.project_id";        
  24.            
  25.         $query = mysqli_query(parent::connect(), $sql);
  26.        
  27.         return $query;
  28.     }

Archivo php 2
Código PHP:
Ver original
  1. if(isset($_POST["id"]) && Database::getIntStatic("id")){
  2.     require_once(ROOT . '/site/articulos.php');
  3.     $objProject = new Articulos();
  4.     $consulta = $objProject->getProjectId($_POST['id']);
  5.  
  6.        
  7.     while( $row= mysqli_fetch_array($consulta)){
  8.        
  9.        
  10.         for($i=0;$i<sizeof($row["examples"]);$i++){
  11.        
  12.             $examples[$row["examples"]] = array(
  13.                 $examples[$row["examples"]] = array(
  14.                     'examples_link'=> $row['example_link'],
  15.                     'example_type' => $row['example_type']
  16.                 )
  17.             );
  18.    
  19.         }
  20.     }
  21.    
  22. echo json_encode($examples);
  23.  
  24. }


Javascript
Código Javascript:
Ver original
  1. function jsonRequest(id){
  2.        
  3.             $.ajax({
  4.                 url: '/agencia-tabata/es/portafolio/showProject.php',
  5.                 type: 'post',
  6.                 dataType:"json",
  7.                 data : {
  8.                     'id':id
  9.                 },
  10.                 success : function(data){
  11.                                       for(i=0;i<data.examples.length;i++){
  12.                       $('.wrapper-medias').append('<img src="'+data.examples[i]+'"/>');
  13.                    
  14.                 }
  15.                                }
  16.  
  17.               }

El id lo recibo en otra funcion mediante atributo.
Hasta ahora es lo que tengo