Forums
This topic is locked
Filtering RecordSet by comma separated values
Posted 13 Nov 2006 16:47:09
1
has voted
13 Nov 2006 16:47:09 fernando delgado posted:
Hi guys,This is my first post as DMXZone customer. It's urgent any help on this, and if nesessary I would pay:
I have 2 tables and 2 simples Recordsets:
(note: Two relationed tables, page_pag and submenu_sub,
relationed by the foreign key idsub_pag which is a VARCHAR for storing comma separated values)
I want 2 things:
1. Depending on the result of the FIRST Recordset, filtering the SECOND Recordset
2. The filter in the Second recorset should filter by a comma separated value idsub_pag
let's suppose that this is the result of first recordset which always will return only one record, result:
id_pag---------idsub_pag-------title_pag
---50------------ 1,2,3--------Our Company
-------- Begin of first Recordset rsPage-----------------
$colname_rsPage = "-1";
if (isset($_GET['id_pag'])) {
$colname_rsPage = (get_magic_quotes_gpc()) ? $_GET['id_pag'] : addslashes($_GET['id_pag']);
}
mysql_select_db($database_cycoplast_conn, $cycoplast_conn);
$query_rsPage = sprintf("SELECT * FROM pages_pag WHERE id_pag = %s", $colname_rsPage);
$rsPage = mysql_query($query_rsPage, $cycoplast_conn) or die(mysql_error());
$row_rsPage = mysql_fetch_assoc($rsPage);
$totalRows_rsPage = mysql_num_rows($rsPage);
--------- end of first Ricordset --------------------
In the second Recordset I need to get all records from the second table submenu_sub WHERE id_sub is equal to each value separated by comma ( idsub_pag=1,2,3 ) returned by the first recordset.
I read in this post that i can use a php variable for storing the field value (idsub_pag) but is not working (Why?),
// Here I try to assign to a php variable a field value result:"1,2,3" from first RecordSet.
$aux = $rsPage->Fields('idsub_pag');
What is worng there ?
and the other question is how to
tell to SQL Querry SELECT * FROM submenu_sub WHERE id_sub = comma separated values sotored in the php variable $aux ?
here is the sencond Recordset where I try to retreive only the records with id_sub
equal to $aux (the comma separated values).
--------- Begin of second Recordset rsSubmenu-----------------
mysql_select_db($database_cycoplast_conn, $cycoplast_conn);
$query_rsSubmenu = "SELECT * FROM submenu_sub WHERE id_sub = $aux"; (how to say $aux to this querry????)
$rsSubmenu = mysql_query($query_rsSubmenu, $cycoplast_conn) or die(mysql_error());
$row_rsSubmenu = mysql_fetch_assoc($rsSubmenu);
$totalRows_rsSubmenu = mysql_num_rows($rsSubmenu);
I should get this result:
id_sub title_sub
1 Activities
2 Recreation
3 Test
--------- end of second Recordset -------------------
Please DMXzone, this is a very important for me, I need to find this solution.
Thanks in advance for yuor help
Fernando Delgado Duran.
______________________
DWMX | PHP | MYSQL
Edited by - fer_75 on 13 Nov 2006 16:48:40
Edited by - fer_75 on 13 Nov 2006 16:50:17
Replies
Replied 14 Nov 2006 10:28:25
14 Nov 2006 10:28:25 fernando delgado replied:
Hi guys,
Please ignore the question, I sorted the problem:
$myvalue = $row_rsPage['idsub_pag']; // $myvalue returns a comma separated value 1,2,3
if ($myvalue=="" $myvalue = 0;
$query_rsSubmenu = "SELECT * FROM submenu_sub WHERE id_sub IN ($myvalue)";
very simple and working graeat.
regards
Fernando Delgado Duran
Please ignore the question, I sorted the problem:
$myvalue = $row_rsPage['idsub_pag']; // $myvalue returns a comma separated value 1,2,3
if ($myvalue=="" $myvalue = 0;
$query_rsSubmenu = "SELECT * FROM submenu_sub WHERE id_sub IN ($myvalue)";
very simple and working graeat.
regards
Fernando Delgado Duran