l0g1t3ch
Goto Top

Daten nur auslesen wenn Bedingung gleich 1

Guten tag liebe Gemeinde,

Ich stosse derzeit an ein problemchen welches mir Kopf zerbrechen verursacht. Warscheinlich weil ich einfach nur blind bin

Folgendes, ich möchte das nur Daten aus meiner MySQL Datenbank gelesen werden wenn die Spalte Frei ( Freigegeben ) = 1
ist.

Aber irgendwie zeigt der mir nur alle Daten an oder gar keine.

Vielleicht kann mir jmd einen Denk anstoss geben.

dies ist quasi die Beiträge ansichts Seite:

<?php require_once('../../Connections/sofageschichten.php'); ?>  
<?php
if (!function_exists("GetSQLValueString")) {  
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")   
{
  if (PHP_VERSION < 6) {
    $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;
}
}

$colname_gb = "-1";  
if (isset($_GET['1'])) {  
  $colname_gb = $_GET['1'];  
}
mysql_select_db($database_sofageschichten, $sofageschichten);
$query_gb = sprintf("SELECT * FROM sofa_gb WHERE frei = %s", GetSQLValueString($colname_gb, "int"));  
$gb = mysql_query($query_gb, $sofageschichten) or die(mysql_error());
$row_gb = mysql_fetch_assoc($gb);
$totalRows_gb = mysql_num_rows($gb);$colname_gb = "-1";  
if (isset($_GET['0'])) {  
  $colname_gb = $_GET['0'];  
}
mysql_select_db($database_sofageschichten, $sofageschichten);
$query_gb = sprintf("SELECT * FROM sofa_gb WHERE frei = %s", GetSQLValueString($colname_gb, "int"));  
$gb = mysql_query($query_gb, $sofageschichten) or die(mysql_error());
$row_gb = mysql_fetch_assoc($gb);
$totalRows_gb = mysql_num_rows($gb);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Gästebuch</title>
<link href="css.css" rel="stylesheet" type="text/css" />  
</head>

<body>
<div class="guestbook">  
<a href="add.php">Beitrag hinzufügen</a>  
<?php do { ?>
  <table>
    <tr class="blue">  
      <td><?php echo $row_gb['id']; ?></td>  
      <td>Author:<?php echo $row_gb['name']; ?></td>  
      <td><?php echo $row_gb['datum']; ?></td>  
      </tr>
    <tr>
      <td>&nbsp;</td>
      <td><?php echo $row_gb['inhalt']; ?></td>  
      <td><?php echo $row_gb['frei']; ?></td>  
    </tr>
  </table>
  <?php } while ($row_gb = mysql_fetch_assoc($gb)); ?>
</div>
</body>
</html>
<?php
mysql_free_result($gb);
?>

und bevor gleich noch einer die Glaskugel braucht oder so hier mal die edit.php um die Beiträge freizugeben.

<?php require_once('../../../Connections/sofageschichten.php'); ?>  
<?php
if (!function_exists("GetSQLValueString")) {  
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")   
{
  if (PHP_VERSION < 6) {
    $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_sofageschichten, $sofageschichten);
$query_gb = "SELECT * FROM sofa_gb";  
$gb = mysql_query($query_gb, $sofageschichten) or die(mysql_error());
$row_gb = mysql_fetch_assoc($gb);
$totalRows_gb = mysql_num_rows($gb);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>Unbenanntes Dokument</title>
<link href="css.css" rel="stylesheet" type="text/css" />  
</head>

<body>
<div class="guestbook">  
<form name="update">  
 Administration<br /><br />
 <table>
   <tr class="grey">  
     <td width="50"><?php echo $row_gb['id']; ?></td>  
     <td width="100">Author:</td>  
     <td width=""><input type="text" value="<?php echo $row_gb['name']; ?>" name="name" /></td>  
   </tr>
   <tr class="grey">  
     <td width="50"></td>  
     <td>Email:</td>
     <td width=""><input type="text" value="<?php echo $row_gb['email']; ?>" name="email" /></td>  
   </tr>
   <tr class="grey">  
     <td width="50"></td>  
     <td>Inhalt:</td>
     <td width=""><textarea cols="40" rows="10"><?php echo $row_gb['inhalt']; ?></textarea></td>  
   </tr>
   <tr class="grey">  
     <td width="50"></td>  
     <td>Freigeben?</td>
     <td width=""><option><input type="radio" name="frei" value="1" />Ja | <input type="radio" name="frei" value="0" />Nein</option></td>  
   </tr>
 </table>
 <input type="submit" />  
 
</form>
</div>
</body>
</html>
<?php
mysql_free_result($gb);
?>

Vielen Dank schonmal Der Ben

Content-Key: 134854

Url: https://administrator.de/contentid/134854

Printed on: April 23, 2024 at 18:04 o'clock

Member: Pixelschubser
Pixelschubser Feb 01, 2010 at 13:35:46 (UTC)
Goto Top
Und wo ist die betreffende Abfrage? Spalte "Freigabe" kann ich net finden ;)
Member: TsukiSan
TsukiSan Feb 01, 2010 at 13:41:29 (UTC)
Goto Top
Und wo ist die betreffende Abfrage? Spalte "Freigabe" kann ich net finden ;)
so ging's mir auch! Aber bin nicht der php-experte.
Vielleicht ist es nur übersehen worden?

Gruss
Tsuki
Member: Pixelschubser
Pixelschubser Feb 01, 2010 at 13:45:05 (UTC)
Goto Top
Schau mal Zeile 39

$query_gb = sprintf("SELECT * FROM sofa_gb WHERE frei = %s", GetSQLValueString($colname_gb, "int"));

da fehlt der wert für %s
Member: L0g1t3ch
L0g1t3ch Feb 01, 2010 at 13:47:08 (UTC)
Goto Top
ich habs grad selbst gemerkt...

und ja es ist übersehen worden... Doofe Where sache grml grml... vielen dank Euch allen