Ver Mensaje Individual
  #4 (permalink)  
Antiguo 29/04/2007, 11:24
Avatar de sumolari
sumolari
 
Fecha de Ingreso: mayo-2006
Ubicación: localhost
Mensajes: 1.367
Antigüedad: 20 años, 4 meses
Puntos: 18
Re: Si la variable de URL no existe, no mostrarla

Una pregunta, si tengo este código para "pillar" datos de la base de datos, cómo puedo hacer para que si no exista muestre el texto que yo quiera.
Mi codigo:
Código PHP:
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

mysql_select_db($database_ffextremo_cms, $ffextremo_cms);
$query_site = "SELECT sitename, sitedesc, siteauthor, sitekeywords, siteurl, siteys, siteyf FROM site";
$site = mysql_query($query_site, $ffextremo_cms) or die(mysql_error());
$row_site = mysql_fetch_assoc($site);
$totalRows_site = mysql_num_rows($site);

$colname_read = "-1";
if (isset(
$_GET['id'])) {
  
$colname_read = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_ffextremo_cms, $ffextremo_cms);
$query_read = sprintf("SELECT * FROM `read` WHERE id = %s", GetSQLValueString($colname_read, "int"));
$read = mysql_query($query_read, $ffextremo_cms) or die(mysql_error());
$row_read = mysql_fetch_assoc($read);
$totalRows_read = mysql_num_rows($read);

$colname_comments = "-1";
if (isset(
$_GET['id'])) {
  
$colname_comments = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_ffextremo_cms, $ffextremo_cms);
$query_comments = sprintf("SELECT * FROM comments WHERE `for` = %s ORDER BY id ASC", GetSQLValueString($colname_comments, "text"));
$comments = mysql_query($query_comments, $ffextremo_cms) or die(mysql_error());
$row_comments = mysql_fetch_assoc($comments);
$totalRows_comments = mysql_num_rows($comments);
?>