Foros del Web » Programando para Internet » PHP »

ayuda con while!!

Estas en el tema de ayuda con while!! en el foro de PHP en Foros del Web. hola estoy modificando el codigo de un script de descargas para que me ponga el titulo de las categorias en el header de la pagina. ...
  #1 (permalink)  
Antiguo 13/02/2008, 05:16
p2pdownloading
Invitado
 
Mensajes: n/a
Puntos:
ayuda con while!!

hola estoy modificando el codigo de un script de descargas para que me ponga el titulo de las categorias en el header de la pagina. Eh copiado el mismo codigo de las categorias y lo modifique para que me tomara los campos de la base de datos en la categoria en que se encuentra, la cuestion es que hay un while mediante el cual el codigo repetia la busqueda de los datos para mostrar las categorias, pero a mi me repite el template del header, necesito sacarlo y ¡no puedo!, si ven otras cosas q esten de mas en el codigo, marquenmelas asi las quito tambien, como veran, no tengo mucha idea y esto lo eh realizado por prueba error y google.
gracias de antemano.

pd: aqui pueden ver como va quedando http://www.software-p2p.com/descargas
si van a las categorias veran que se repite el header...

Código PHP:
    if(isset($_POST['sub']))
{
    
    
$cID $_POST['cid'];
    
    
$sql mysql_query("SELECT cPwd FROM ".DB_PREFIX."categories WHERE cID = '".$cID."'");    
    
$r=mysql_fetch_array($sql);
    
    
    if(
$cat_pass === $cPwd)
{
    
    
$cat_page "{*LOCKED_GRANT*}<meta http-equiv='Refresh' content='2;url=index.php?action=category&id=".$cID."'>";


} else {

    if(
$_GET['id'] != '')
{
    
$cID mysql_real_escape_string(stripslashes($_GET['id']));
} else {
    
$cID '0';
}

    
$check_sql mysql_query("SELECT * FROM ".DB_PREFIX."categories WHERE cID = '".$cID."'");
    if(
$cID '0')
{
    if(
mysql_num_rows($check_sql) == '0')
{
    echo 
"<meta http-equiv='Refresh' content='0;url=index.php?action=failed&fail=cInvalid'>";
    exit;
} else {
    
$cs=mysql_fetch_array($check_sql);
    

    if(
$cPwd != '')
{
    if(
$_SESSION['cat_'.$cID] != $cPwd)
{
    echo 
"<meta http-equiv='Refresh' content='0;url=index.php?action=failed&locked=".$cID."'>";
    exit;
}}}
}

    
    
    
$tr_sql mysql_query("SELECT * FROM ".DB_PREFIX."templates WHERE tID = '".$theme."' && tmName = 'header'");
    
$tr=mysql_fetch_array($tr_sql);
    
$tableRow=$tr["template"];
        
     
    
$sql mysql_query("SELECT * FROM ".DB_PREFIX."categories WHERE cID = '".$cID."' ORDER BY cOrder ASC");

    if(
mysql_num_rows($sql) == '0')
{
        
$cName="hola";
    
$cDesc=$r["cDesc"];
     
        
$cat_row str_replace("{php=cat_name}"$cName$cat_row);
       
    



} else { 


        while(
$r=mysql_fetch_array($sql))
    
{
    
$cat_ID=$r["cID"];
    
$cName=$r["cName"];
    
$cDesc=$r["cDesc"];


    if(
$scCount != '0')
{       
        
$sc_sql mysql_query("SELECT cID, cName, dDesc FROM ".DB_PREFIX."categories WHERE cID = '".$cID."'");
    

        while(
$sc=mysql_fetch_array($sc_sql))
{


    if(
$scC != '0')
{
    
}}
}    

    
$cat_row str_replace("{php=cat_id}"$cat_ID$tableRow);
    
$cat_row str_replace("{php=cat_name}"$cName$cat_row);
    
$cat_row str_replace("{php=cat_desc}"$cDesc$cat_row);


    if(
$cPwd != '')
{
    
$locked "<b>{*LOCKED*}:</b>&nbsp;";
    
$cat_row str_replace("{php=cat_pwd}"$locked$cat_row);
} else {
    
$cat_row str_replace("{php=cat_pwd}"""$cat_row);
}

    
$cat_page .= $cat_row;
}
    

    if(
$cID == '0')
{
    if(
$allFiles == '1')
{
    

    
$all_scCount '0';
    
$all_dCount '0';

    
$a_sql mysql_query("SELECT scCount, dCount FROM ".DB_PREFIX."categories ORDER BY cID ASC");
    while(
$ar=mysql_fetch_array($a_sql))
{
    
$all_dCount += $ar["dCount"];
}
    
$all_row str_replace("{php=sub_cats}"$all_scCount$all_row);
    
$all_row str_replace("{php=total_files}"$all_dCount$all_row);

    
$cat_page .= $all_row;
}}
}
}
    
$cat_page lang_convert($cat_page);






    if(
$_GET['id'] != '')
{
    
$scribeID $_GET['id'];
} else {
    
$scribeID '0';
}





// Start to display downloads if it isn't the main category! SUBCATEGORIAS----------------------------------------------------------

    
if($cID '0')
{
    echo 
"";



    
$tr_sql mysql_query("SELECT * FROM ".DB_PREFIX."templates WHERE tID = '".$theme."' && tmName = 'cat_names'");
    
$tr=mysql_fetch_array($tr_sql);
    
$tableRow=$tr["template"];

    
$sql mysql_query("SELECT noFiles FROM ".DB_PREFIX."categories WHERE cID = '".$cID."'");    
    
$r=mysql_fetch_array($sql);
    
$limit=$r["noFiles"];

    
$sql mysql_query("SELECT dID, dName, FROM ".DB_PREFIX."downloads WHERE cID = '".$cID."' && sticky = '1' && approved = '1' ORDER BY dID DESC");
    
    
$noSticky '0';
    if(
mysql_num_rows($sql) > '0')
{
    
$noSticky mysql_num_rows($sql);
    
$limit -= $noSticky;

    while(
$r=mysql_fetch_array($sql))
{
    
$dID=stripslashes($r["dID"]);
    
$dName=stripslashes($r["dName"]);



    
$down_row str_replace("{php=down_id}"$dID$tableRow);
    
$down_row str_replace("{php=cat_name}"$dName$down_row);
        



    
$down_page .= $down_row;
}}

    
$query_count    "SELECT * FROM ".DB_PREFIX."downloads WHERE cID = '".$cID."' && sticky = '0' && approved = '1'";    
        
$result_count   mysql_query($query_count);    
        
$totalrows      mysql_num_rows($result_count);
        
    if(
is_numeric($_GET['page']))
{
    
$page $_GET['page'];
} else {
        
$page '1';
}       

    
$numofpages $totalrows $limit;
       
$limitvalue $page $limit - ($limit);

    if(isset(
$_POST['sort_sub']))
{
    
$sort htmlentities($_POST['sort'], ENT_QUOTES);
    
$order htmlentities($_POST['order'], ENT_QUOTES);
} else {
    
$sort "dID";
    
$order "DESC";
}

        
$query  "SELECT dID, dName,  count FROM ".DB_PREFIX."downloads WHERE cID = '".$cID."' && sticky = '0' && approved = '1' ORDER BY ".$sort." ".$order." LIMIT $limitvalue, $limit";        
       
$result mysql_query($query);

    if(
$noSticky == '0' && $totalrows == '0')
{
    

} else {

    while(
$r=mysql_fetch_array($result))
{

    
$dID=stripslashes($r["dID"]);
    
$dName=stripslashes($r["dName"]);
    

        
    
$down_row str_replace("{php=down_id}"$dID$tableRow);
    
$down_row str_replace("{php=cat_name}"$dName$down_row);


    
$down_page .= $down_row;
}

    
$page_nav page_nav("action=category&id=".$cID);

    
$pagination "
    "
.$page_nav."    
    "
;
}

    
$down_page lang_convert($down_page);

}


    




// Pull the header template
$h_sql mysql_query("SELECT * FROM ".DB_PREFIX."templates WHERE tID = '".$theme."' && tmName = 'header'");
$h=mysql_fetch_array($h_sql);
$header=$h["template"]; 
  #2 (permalink)  
Antiguo 13/02/2008, 05:45
 
Fecha de Ingreso: octubre-2003
Ubicación: Zaragoza (España)
Mensajes: 14
Antigüedad: 20 años, 6 meses
Puntos: 0
Re: ayuda con while!!

por lo que veo a simple vista:
- el array de la consulta la guardas en $sc, pero luego intentas reemplazar de $cat_row.

deberia ser

Cita:
$cat_row = str_replace("{php=cat_desc}", $cDesc, $sc['nombre_campo']);
Código PHP:
while($sc=mysql_fetch_array($sc_sql))
{


    if(
$scC != '0')
{
    
}}
}    

    
$cat_row str_replace("{php=cat_id}"$cat_ID$tableRow);
    
$cat_row str_replace("{php=cat_name}"$cName$cat_row);
    
$cat_row str_replace("{php=cat_desc}"$cDesc$cat_row); 
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:19.