Foros del Web » Programando para Internet » PHP »

Problema al no tener variable en el url

Estas en el tema de Problema al no tener variable en el url en el foro de PHP en Foros del Web. Saludos, tengo un sistema donde extraigo datos segun el id al que llame pero al momento de no tener un id, es decir, que el ...
  #1 (permalink)  
Antiguo 20/08/2008, 07:59
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Problema al no tener variable en el url

Saludos, tengo un sistema donde extraigo datos segun el id al que llame pero al momento de no tener un id, es decir, que el URL este limpio (ejemplo: http://www.sitio.com/ficha.php) me manda este mensaje

Error en consulta: , error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id ASC' at line 1

pero si tngo la direccion http://www.sitio.com/ficha.php?id=2 obvio me salen los resultados...

aqui esta mi codigo, trate de hacer algo co un if pero nada..
Código PHP:
<?php include('conect.php');

// Variables de Configuración -----------------------------------
// Define el numero de Filas
$n_filas=3;

//***************************************************************
@$cat=$_REQUEST['id'];
//$cat=6;

$fotos = array();
    
$sql="SELECT * FROM galeria where prod_id= $cat  ORDER BY id ASC";
    
$sql_exec=mysql_query($sql) or die("Error en consulta: $sql_exec, error: "mysql_error());
    
$sql2="SELECT * FROM galeria where prod_id= $cat  ORDER BY id ASC";
    
$sql_exec2=mysql_query($sql2) or die("Error en consulta: $sql_exec2, error: "mysql_error());

    
/*while($row=mysql_fetch_assoc($sql_exec)){
            $tottal=mysql_affected_rows(); // Calculo el numero total de itms a listar
            }*/
$tottal=113;
// ------------------------------------------------------------------------------------------------------------------
$vert=$tottal/$n_filas;
$vert=round($vert);

?>
<link href="../estilos.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../highslide/highslide.js"></script>


<!-- 
    2) Optionally override the settings defined at the top
    of the highslide.js file. The parameter hs.graphicsDir is important!
-->

<script type="text/javascript">    
    hs.graphicsDir = '../highslide/graphics/';
    hs.outlineType = 'rounded-white';
</script>


<!-- 
    3) These CSS-styles are necessary for the script to work. You may also put
    them in an external CSS-file. See the webpage for documentation.
-->

<style type="text/css">
.highslide-wrapper div {
    font-family: Verdana, Helvetica;
    font-size: 10pt;
}
.highslide {
    cursor: url(../highslide/graphics/zoomin.cur), pointer;
    outline: none;
    text-decoration: none;
}
.highslide-active-anchor img {
    visibility: hidden;
}
.highslide img {
    border: 2px solid gray;
}
.highslide:hover img {
    border: 2px solid white;
}

.highslide-wrapper, .rounded-white {
    background: white;
}
.highslide-image {
    border: 2px solid white;
}
.highslide-image-blur {
}
.highslide-caption {
    display: none;
    
    border: 2px solid white;
    border-top: none;
    font-family: Verdana, Helvetica;
    font-size: 10pt;
    padding: 5px;
    background-color: white;
}
.highslide-loading {
    display: block;
    color: black;
    font-size: 8pt;
    font-family: sans-serif;
    font-weight: bold;
    text-decoration: none;
    padding: 2px;
    border: 1px solid black;
    background-color: white;
    
    padding-left: 22px;
    background-image: url(../highslide/graphics/loader.white.gif);
    background-repeat: no-repeat;
    background-position: 3px 1px;
}
a.highslide-credits,
a.highslide-credits i {
    padding: 2px;
    color: silver;
    text-decoration: none;
    font-size: 10px;
}
a.highslide-credits:hover,
a.highslide-credits:hover i {
    color: white;
    background-color: gray;
}

a.highslide-full-expand {
    background: url(../highslide/graphics/fullexpand.gif) no-repeat;
    display: block;
    margin: 0 10px 10px 0;
    width: 34px;
    height: 34px;
}

</style>
<link href="../css/estilo.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style2 {color: #DCDBA0}
-->
</style>
<table width="260" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top"><br />
      <table width="220" height="134" border="0" align="center" cellpadding="0" cellspacing="2">
        <!--DWLayoutTable-->
        <tr>
          <td width="220" height="64"><table width="220" height="64" border="0" align="center" cellpadding="0" cellspacing="5">
              <?php if (empty($cat)) { echo 'debe seleccionar un inmueble'; }  
        
$a=0;// Colocando el contador horizontal en 0
        
$i=1;// Colocando el contador vertical en 0
        
$w=0;//Colocando un contador para el mensaje de "No hay articulos en esta acategoria"
        
            
while($row=mysql_fetch_assoc($sql_exec)){
            
$w=w+1;
                if (
$a==0){
                echo 
'<tr>';
                }
                
$a=$a+1;
                
$fotos[$i.'-'.$a] = $row['img'];
                
                echo 
"<td height='85' width='64' border='0' ><a href='../galeria/".$row['img']."' class='highslide' onclick='return hs.expand(this)'><img src='../galeria/".$row['img']."' width='85' height='64' border='0'  alt='Ampliar'/></a><br>
                <a href='elim_galeria.php?id="
.$row['id']."'><div align='center'>eliminar</div></a>";
            
                
$r=$a;// contador remanente para listar imagenes sin exceso
                
                    
if ($a >= $n_filas) {
                    
$a=0;// reiniciando el contador horizontal
                    
$i=$i+1;// aumentando el contador vertical
                    
echo '</tr>';
                    } 
            if (empty(
$row)) {
        echo
"<table width='0' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='257'><div align='center'>No hay articulos en esta categoria </div></td>
          </tr>
        </table>
        "
;
        break 
1;}
            
            }
            
         echo 
'</td>'
        
?>
              <?php /*if (empty($w)) {
        echo"<table width='0' border='0' align='center' cellpadding='0' cellspacing='0'>
          <tr>
            <td width='492'><div align='center'>No hay articulos en esta categoria </div></td>
          </tr>
        </table>
        ";
        exit;}
        */
?>
          </table></td>
        </tr>
        <tr>
          <td valign="top"><div align="center"><span class="textofichaprod"><span class="style2">-</span>Seleccione una imgen para ampliar</span></div></td>
        </tr>
      </table>
      <br /></td>
  </tr>
</table>
sera q pueden hecharme una mano para saber en q ando fallando???

gracias
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 20/08/2008, 08:04
 
Fecha de Ingreso: agosto-2007
Mensajes: 345
Antigüedad: 16 años, 7 meses
Puntos: 21
Respuesta: Problema al no tener variable en el url

de primeras creo que podrias solucionarlo asi:

Código PHP:
if(!isset($_GET["id"]))
{
   
$id=1//aqui pones el id que se mostrara en caso de no obtener ninguno. 
}
else
{
   
$id=$_GET["id"]; //el id que llega con la página.

Si lo utilizas asi debes tener cuidado a la hora de recoger el id que viene por $_GET
  #3 (permalink)  
Antiguo 20/08/2008, 08:41
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 7 meses
Puntos: 28
Respuesta: Problema al no tener variable en el url

solucionado... gracias amigo!!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
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 19:37.