close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Filtering recordset with others recordsets row value

Thread began 12/08/2009 11:48 pm by austin_kyo371741 | Last modified 12/11/2009 5:07 pm by austin_kyo371741 | 5726 views | 4 replies |

austin_kyo371741

Filtering recordset with others recordsets row value

Hi, i am trying to filter a recordsets with another recordsets row value

mysql_select_db($database_c_conn, $c_conn);
$query_R1_RS = "SELECT * FROM R1 ORDER BY ID DESC";
$R1_RS = mysql_query($query_R1_RS, $c_conn) or die(mysql_error());
$row_R1_RS = mysql_fetch_assoc($R1_RS);
$totalRows_R1_RS = mysql_num_rows($R1_RS);

mysql_select_db($database_c_conn, $c_conn);
$query_Member_RS = "SELECT * FROM record_list WHERE `member Name` = '$row_R1_RS['member_name'] '";
$Member_RS = mysql_query($query_Member_RS, $c_conn) or die(mysql_error());
$row_Member_RS = mysql_fetch_assoc($Member_RS);
$totalRows_Member_RS = mysql_num_rows($Member_RS);

it don't work, uncorrect syntax :(

can some 1 show me the right syntax ?

Thanks

Sign in to reply to this post

Jason ByrnesWebAssist

you should add the first recordset value to the second recordset where clause as a parameter.


Double click the second recordset and go to advanced view.

Set the SQL to;
SELECT * FROM record_list WHERE `member Name` = paramMemberName

In the parameters section, click the plus button to create a new parameter:
Name: paramMemberName
Type: Text
Default Value: - 1
Run Time value: $row_R1_RS['member_name']

Sign in to reply to this post

austin_kyo371741

Originally Said By: Jason Byrnes
  you should add the first recordset value to the second recordset where clause as a parameter.


Double click the second recordset and go to advanced view.

Set the SQL to;
SELECT * FROM record_list WHERE `member Name` = paramMemberName

In the parameters section, click the plus button to create a new parameter:
Name: paramMemberName
Type: Text
Default Value: - 1
Run Time value: $row_R1_RS['member_name']  



Hi John, i did as you told me, but it still din't work... i think there must be some things wrong with my script.. and i had create a testing page to test it.

here is the whole page script:

<?php require_once('../Connections/c_conn.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_c_conn, $c_conn);
$query_Product_RS = "SELECT * FROM R1 ORDER BY ID DESC";
$R1_RS = mysql_query($query_R1_RS, $c_conn) or die(mysql_error());
$row_R1_RS = mysql_fetch_assoc($R1_RS);
$totalRows_R1_RS = mysql_num_rows($R1_RS);

$colname_member_RS = "-1";
if (isset($row_R1_RS['member_name'])) {
$colname_member_RS = (get_magic_quotes_gpc()) ? $row_R1_RS['member_name'] : addslashes

($row_R1_RS['member_name']);
}
mysql_select_db($database_c_conn, $c_conn);
$query_member_RS = sprintf("SELECT * FROM member WHERE 'member_name' = %s", GetSQLValueString

($colname_member_RS, "text"));
$member_RS = mysql_query($query_member_RS, $c_conn) or die(mysql_error());
$row_member_RS = mysql_fetch_assoc($member_RS);
$totalRows_member_RS = mysql_num_rows($member_RS);
?>

<!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>Untitled Document</title>
</head>

<body>
<p><?php echo $row_R1_RS['member_name']; ?></p>
<p><?php echo $row_member_RS['member_name']; ?></p>

</body>
</html>
<?php

it able to display "member_name" from R1_RS recordset, but can't display "member_name" from member_RS recordset... :(

Sign in to reply to this post

Jason ByrnesWebAssist

That code looks correct.


Are you sure the member name that is being displayed from R1_RS exists in the member table?


Here is something to try, add the following code just after the <body> tag:
[php]<?php echo($query_member_RS); ?>



this will write the sql being used to the screen. copy this SQL, then start a new recordset. In advanced view, past this SQL then pres the test button.

Please post back the results of the test and the SQL.
also double check that the value being searched for actually exists in the members table.

Sign in to reply to this post

austin_kyo371741

Originally Said By: Jason Byrnes
  That code looks correct.


Are you sure the member name that is being displayed from R1_RS exists in the member table?


Here is something to try, add the following code just after the <body> tag:
[php]<?php echo($query_member_RS); ?>



this will write the sql being used to the screen. copy this SQL, then start a new recordset. In advanced view, past this SQL then pres the test button.

Please post back the results of the test and the SQL.
also double check that the value being searched for actually exists in the members table.  



Hi Jason,

I tried it again today, and it work!!! I don't know what is going on, it din't work when i tried yesterday..maybe some kind of bugs i think.. Anyway, Thanks :)

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...