arunkar Posted April 3, 2008 Share Posted April 3, 2008 Hi, Being new to php I'm unable to get this right. I'm trying to pass a dynamic value generated by SQL to another page on clicking the value. the value is stored in the variable $field (below). Now I get the varible in the next page and not the value how do I do it? <?php foreach($rowTotJoyCard as $field){ if($field >0){?> <a href="javascript:popUp([b]'details2.php?MR=TotJoyCard&Reg=Total Joy Card Signups&Tot=$field')[/b]"><?php echo $field; ?></a><?php } else{echo "0";} } ?> is there a way? thanks Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 How are you passing the value from the previous page? Are you posting it? Are you using a session variable? Quote Link to comment Share on other sites More sharing options...
arunkar Posted April 3, 2008 Author Share Posted April 3, 2008 Caesar , I'm passing the value generated by MySQL query. its the $field value that Im passing to the next page. below is the code does the passing of the value. <? $NewJoyCard = mysql_query("SELECT count(*) FROM subscribers WHERE formid = 4 and DATE(FROM_UNIXTIME(requestdate)) = CURRENT_DATE()"); php foreach($rowTotJoyCard as $field){ if($field >0){?> <a href="javascript:popUp('details2.php?MR=TotJoyCard&Reg=Total Joy Card Signups&Tot=$field')"><?php echo $field; ?></a><?php } else{echo "0";} } ?> Thanks Quote Link to comment Share on other sites More sharing options...
devstudio Posted April 3, 2008 Share Posted April 3, 2008 Is it Tot getting lost? Is it being assigned as "$field"? If so, fix is below, $field is being printed in the javascript popUp literally. <? $NewJoyCard = mysql_query("SELECT count(*) FROM subscribers WHERE formid = 4 and DATE(FROM_UNIXTIME(requestdate)) = CURRENT_DATE()"); php foreach($rowTotJoyCard as $field){ if($field >0){?> <a href="javascript:popUp('details2.php?MR=TotJoyCard&Reg=Total Joy Card Signups&Tot=<?php echo $field; ?>')"><?php echo $field; ?></a><?php } else{echo "0";} } ?> Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 The page isn't right. <? $NewJoyCard = mysql_query("SELECT count(*) FROM subscribers WHERE formid = 4 and DATE(FROM_UNIXTIME(requestdate)) = CURRENT_DATE()"); php foreach($rowTotJoyCard as $field){ if($field >0){?> <a href="javascript:popUp('details2.php?MR=TotJoyCard&Reg=Total Joy Card Signups&Tot=$field')"><?php echo $field; ?></a><?php } else{echo "0";} } ?> What's with the php before your foreach loop? <?php $NewJoyCard = mysql_query("SELECT count(*) FROM subscribers WHERE formid = 4 and DATE(FROM_UNIXTIME(requestdate)) = CURRENT_DATE()"); foreach($rowTotJoyCard as $field) { if($field >0){ echo'<a href="javascript:popUp(\'details2.php?MR=TotJoyCard&Reg=Total Joy Card Signups&Tot=$field\')">'.$field.'</a>'; } else { echo "0"; } } ?> Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 3, 2008 Share Posted April 3, 2008 Anyway, if I'm seeing this right...your loop is wrong. $rowTotJoyCard isn't an array. You can't loop it. P.S....print out the $rowTotJoyCard and see what it outputs before your loop. <?php $NewJoyCard = mysql_query("SELECT count(*) FROM subscribers WHERE formid = 4 and DATE(FROM_UNIXTIME(requestdate)) = CURRENT_DATE()"); print('<pre>'); print_r($rowTotJoyCard); print('</pre>'); ?> Quote Link to comment Share on other sites More sharing options...
arunkar Posted April 3, 2008 Author Share Posted April 3, 2008 Thanks devstudio and Caesar, it was not printing the value of $field and printing $field it self. Now it works like charm... btw, actually I'm using a while loop to run the query. thanks again Caesar. cheers Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.