Udtræk af Sql i php - fejl/problemer med kode
Hej,Efter forbindelsen til databasen er oprettet køres:
<?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;
}
}
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
$Navn_Recordset1 = "Anders";
if (isset($_GET['Navn'])) {
$Navn_Recordset1 = $_GET['Navn'];
}
$Bynavn_Recordset1 = "Skagen";
if (isset($_GET['Bynavn'])) {
$Bynavn_Recordset1 = $_GET['Bynavn'];
}
$Land_Recordset1 = "Danmark";
if (isset($_GET['Land'])) {
$Land_Recordset1 = $_GET['Land'];
}
mysql_select_db($database_Kontakter, $Mine_kontakter);
$query_Recordset1 = sprintf("SELECT * FROM Kontakter WHERE %s LIKE %s AND %s LIKE %s AND %s LIKE %s ORDER BY %s ASC", GetSQLValueString($Navn_Recordset1, "text"),GetSQLValueString($Navn_Recordset1, "text"),GetSQLValueString($Bynavn_Recordset1, "text"),GetSQLValueString($Bynavn_Recordset1, "text"),GetSQLValueString($Land_Recordset1, "text"),GetSQLValueString($Land_Recordset1, "text"),GetSQLValueString($Navn_Recordset1, "text"));
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Mine_kontakter) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
Søgeordene (fra en formular på en søgeside) vises vha:
<?php echo $_GET['Navn']; ?>
for Navn, Bynavn og Land. Ingen problemer her.
Nu burde resultat(erne) fra to andre rækker (Telefon og Mobil) vises for de givne søgeord. Her bruges:
<?php echo $row_Recordset1['Telefon']; ?> og <?php echo $row_Recordset1['Mobil']; ?>
Resultater er at HELE databasens indhold vises (Navn, Bynavn, Land, Telefon, Mobil) - hvorfor?
(Siden er lavet i Dreamweaver)
