Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Filter records using variables

New Here ,
Aug 11, 2007 Aug 11, 2007
Using PHP/MySQL and DW8

I have 2 pages. First page displays a number of collections. And the second page is my detail page. When I select a collection I want to pass through the collection name to the detail page. So it only displays the images for that collection. Then I will pass id & collection name to another detailview page for a specific item.

I can pass them through the URL like collections.php?name=whatever (using colname in advanced RS). But I keep getting an error on the detail page.

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 'WHERE client = 'client'' at line 1

Can how help me do this....

COLLECTIONS PAGE:

<?php require_once('../Connections/cmsConn.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_cmsConn, $cmsConn);
$query_Recordset1 = "SELECT * FROM `work`";
$Recordset1 = mysql_query($query_Recordset1, $cmsConn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Document</title>
</head>

<body>
<a href="test2.php?id=<?php echo $row_Recordset1['id']; ?>&client=<?php echo $row_Recordset1['client']; ?>"><?php echo $row_Recordset1['client']; ?></a>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

DETAIL PAGE:

<?php require_once('../Connections/cmsConn.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;
}
}

$colname_Recordset1 = "-1";
if (isset($_GET['id'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
$varclient_Recordset1 = "client";
if (isset($row_Recordset1['client'])) {
$varclient_Recordset1 = (get_magic_quotes_gpc()) ? $row_Recordset1['client'] : addslashes($row_Recordset1['client']);
}
mysql_select_db($database_cmsConn, $cmsConn);
$query_Recordset1 = sprintf("SELECT * FROM `work` WHERE id = %s & WHERE client = %s", GetSQLValueString($colname_Recordset1, "text"),GetSQLValueString($varclient_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $cmsConn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?php echo $row_Recordset1['client']; ?>
<?php echo $row_Recordset1['brief']; ?>
<?php echo $row_Recordset1['id']; ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
TOPICS
Server side applications
318
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 11, 2007 Aug 11, 2007
bitmapboy wrote:

>
> DETAIL PAGE:
> $colname_Recordset1 = "-1";
> if (isset($_GET['id'])) {
> $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] :
> addslashes($_GET['id']);
> }
> $varclient_Recordset1 = "client";
> if (isset($row_Recordset1['client'])) {
> $varclient_Recordset1 = (get_magic_quotes_gpc()) ? $row_Recordset1['client']
> : addslashes($row_Recordset1['client']);
> }
> mysql_select_db($database_cmsConn, $cmsConn);
> $query_Recordset1 = sprintf("SELECT * FROM `work` WHERE id = %s & WHERE client
> = %s", GetSQLValueString($colname_Recordset1,
> "text"),GetSQLValueString($varclient_Recordset1, "text"));


What do you get when you echo:
$query_Recordset1 =
sprintf("SELECT * FROM `work`
WHERE id = %s &
WHERE client = %s",
GetSQLValueString($colname_Recordset1,"text"),
GetSQLValueString($varclient_Recordset1, "text"));

I don't like the "&", try "AND" or "&&", and is the "id" text?
Mick


> $Recordset1 = mysql_query($query_Recordset1, $cmsConn) or die(mysql_error());
> $row_Recordset1 = mysql_fetch_assoc($Recordset1);
> $totalRows_Recordset1 = mysql_num_rows($Recordset1);
> ?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 11, 2007 Aug 11, 2007
On Sat, 11 Aug 2007 10:55:56 -0400, Mick White
<himselfBOGUS@mickweb.com> wrote:

>What do you get when you echo:
>$query_Recordset1 =
>sprintf("SELECT * FROM `work`
>WHERE id = %s &
>WHERE client = %s",
>GetSQLValueString($colname_Recordset1,"text"),
>GetSQLValueString($varclient_Recordset1, "text"));


You wouldn't want two WHERE's in there. This might be closer:

What do you get when you echo:
$query_Recordset1 =
sprintf("SELECT * FROM `work`
WHERE id = %s AND client = %s",
GetSQLValueString($colname_Recordset1,"text"),
GetSQLValueString($varclient_Recordset1, "text"));


Gary
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 12, 2007 Aug 12, 2007
LATEST
Thanks.

That stopped the error, but only display the detail for 1 record. I simply need it to filter by id and collection name.

http://localhost:8888/test/detail.php?id=2&col=55

Like this.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines