Forums

PHP

This topic is locked

Filtering a recordset with a variable from another

Posted 03 Jul 2003 11:18:52
1
has voted
03 Jul 2003 11:18:52 Jim Balchin posted:
Hey all ;]

Have trouble getting this tutorial to work correctly:-

www.dmxzone.com/ShowDetail.asp?NewsId=1446

Can someone explain a little more. Im not stupid (I think!) but cant seem to get it to work correctly. Im using PHP/MySQL

Im using rsACTIVE.Fields.Item("JobID".Value as my run time variable. I have a recordset above this one called 'rsACTIVE' and it has a field 'JobID'.

Some help would be really appreciated.

Cheers.

Replies

Replied 03 Jul 2003 18:20:35
03 Jul 2003 18:20:35 Steffen Hallbauer replied:
Hallo Jimmy
I don't know if this helps, but here is my version i used already and works - if I got your problem right:

//here is my first recordset

$query_insforderung = sprintf("SELECT id, firmname, round(firmbetrag,2), id_insolvenz FROM insforderung WHERE firmname like '%%%s%%' AND firmbetrag = '%s'", $colname_insforderung,$colname2_insforderung);
$insforderung = mysql_query($query_insforderung, $sperling) or die(mysql_error());
$row_insforderung = mysql_fetch_assoc($insforderung);
$totalRows_insforderung = mysql_num_rows($insforderung);

//here comes the check if the variable for my second recordset excists
//i create a variable with a value so it finds something and no error can occure just incase it isn't set yet
//$asd is the value i want to give the second recordset

$inso='4';
if (!isset($inso)){ $asd =$inso ;};

//now i overwrite the value of $asd with the one from the first recordset

if (isset($row_insforderung['id_insolvenz'])){$asd=$row_insforderung['id_insolvenz'] ;};
//here is the new recordset...
mysql_select_db($database_sperling, $sperling);
$query_con_verf = "SELECT * FROM insverfahr WHERE id_insolvenz ='$asd'";

Thats ist - hope that's it!
Regard Steffen<b></b><b></b><font color=red></font id=red><font color=black></font id=black>
Replied 04 Jul 2003 12:20:44
04 Jul 2003 12:20:44 Jim Balchin replied:
Thanks man, that worked great. The only problem Im having now is when i use a repeat region on the second record set it repeatidly displays the first result from the query. Any Idea's?

Thanks ;]


Jim.
Replied 04 Jul 2003 12:24:52
04 Jul 2003 12:24:52 Steffen Hallbauer replied:
Could you display the code?
I'll give it a try...

Edited by - hallbast on 04 Jul 2003 12:25:18
Replied 04 Jul 2003 15:29:01
04 Jul 2003 15:29:01 Jim Balchin replied:
Heres the code :-

&lt;?php require_once('Connections/mAROFFICE.php'); ?&gt;
&lt;?php
$maxRows_rs1 = 10;
$pageNum_rs1 = 0;
if (isset($HTTP_GET_VARS['pageNum_rs1'])) {
$pageNum_rs1 = $HTTP_GET_VARS['pageNum_rs1'];
}
$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;

mysql_select_db($database_mAROFFICE, $mAROFFICE);
$query_rs1 = "SELECT * FROM tbljobs WHERE JobActive = 1";
$query_limit_rs1 = sprintf("%s LIMIT %d, %d", $query_rs1, $startRow_rs1, $maxRows_rs1);
$rs1 = mysql_query($query_limit_rs1, $mAROFFICE) or die(mysql_error());
$row_rs1 = mysql_fetch_assoc($rs1);

if (isset($HTTP_GET_VARS['totalRows_rs1'])) {
$totalRows_rs1 = $HTTP_GET_VARS['totalRows_rs1'];
} else {
$all_rs1 = mysql_query($query_rs1);
$totalRows_rs1 = mysql_num_rows($all_rs1);
}
$totalPages_rs1 = ceil($totalRows_rs1/$maxRows_rs1)-1;

$maxRows_rs2 = 10;
$pageNum_rs2 = 0;
if (isset($HTTP_GET_VARS['pageNum_rs2'])) {
$pageNum_rs2 = $HTTP_GET_VARS['pageNum_rs2'];
}
$startRow_rs2 = $pageNum_rs2 * $maxRows_rs2;

$colname_rs2 = "1";
if (isset($row_rs1['JobID'])) {
$colname_rs2 = (get_magic_quotes_gpc()) ? $row_rs1['JobID'] : addslashes($row_rs1['JobID']);
}
mysql_select_db($database_mAROFFICE, $mAROFFICE);
$query_rs2 = sprintf("SELECT * FROM tbl_op_data WHERE JobID = %s", $colname_rs2);
$query_limit_rs2 = sprintf("%s LIMIT %d, %d", $query_rs2, $startRow_rs2, $maxRows_rs2);
$rs2 = mysql_query($query_limit_rs2, $mAROFFICE) or die(mysql_error());
$row_rs2 = mysql_fetch_assoc($rs2);

if (isset($HTTP_GET_VARS['totalRows_rs2'])) {
$totalRows_rs2 = $HTTP_GET_VARS['totalRows_rs2'];
} else {
$all_rs2 = mysql_query($query_rs2);
$totalRows_rs2 = mysql_num_rows($all_rs2);
}
$totalPages_rs2 = ceil($totalRows_rs2/$maxRows_rs2)-1;
?&gt;


Cheers man. Err could you explain what you change? Thanks ;]

Reply to this topic