The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Want to Display output from a foreach in a template
Ok
Simple thing I have a Form that people can put membership numbers into, then a script will check in Mysql if they are or not Then print out Yes or No and expiry if Yes Works fine for single lookup but make it do more lookup ie 8 the output templete just shows last lookup in the list result. if you just print the out ot the screen all the 8 results are there Help Code:
foreach ( $_POST as $name => $value) { if ((stristr($name,'membership')) && ($value !=0 ) ) { // Check to See if Member $check_if_member=$db->query_first("SELECT MemberID, DateExpire FROM ~~~~~ WHERE MemberID = $value"); if ($check_if_member){ $membership_number=$value; $Expire_Date=$check_if_member['DateExpire']; } else { $membership_number=$value; $Expire_Date="" ; } print_r ($check_if_member) ; echo "<br /> $name, $value <br />" ; } eval('print_output("'. fetch_template('rsoc_member_check_output') . '");'); membership_number2, 1 membership_number3, 2 membership_number4, 3 membership_number5, 2 membership_number6, 34 Array ( [MemberID] => 14**** [DateExpire] => *******) membership_number8, 14**** What do i need to either do in the script or template to output the above ? * = protect data Giz |
#2
|
|||
|
|||
I think what I'd do is make the entire list one variable in the main template, then create another small template to display one membership line. Then construct that list variable in the loop so it will be ready to use when you call "fetch_template" for the main template at the end.
|
#3
|
|||
|
|||
Thanks for the reply mate, can u give some demo code of your suggestion
Tar muchly Gizmo |
#4
|
|||
|
|||
Something like this (I didn't actually try this so you'll have to excuse me if there's some small error:
Code:
$memlist = ''; foreach ( $_POST as $name => $value) { if ((stristr($name,'membership')) && ($value !=0 ) ) { // Check to See if Member $check_if_member=$db->query_first("SELECT MemberID, DateExpire FROM ~~~~~ WHERE MemberID = $value"); if ($check_if_member){ $membership_number=$value; $Expire_Date=$check_if_member['DateExpire']; } else { $membership_number=$value; $Expire_Date="" ; } print_r ($check_if_member) ; //echo "<br /> $name, $value <br />" ; eval('$memlist .= "' . fetch_template('membership_template') . '";'); } eval('print_output("'. fetch_template('rsoc_member_check_output') . '");'); In fact, if you wanted you could just use Code:
$memlist .= "<br /> $membership_number, $Expire_Date<br />"; In any case, in your 'rsoc_member_check_output' template just put $memlist where you want the list. --------------- Added [DATE]1258324902[/DATE] at [TIME]1258324902[/TIME] --------------- Sorry, I realized that you want to use $membership_number and $Expire_Date instead of $name and $value (which I guess were in the echo call for debugging?) so I changed the above. |
#5
|
|||
|
|||
Sorted Mate was nearly there but u helped with the last bit
Cheers again Mate Code:
// Set Up the Array $member_output = ''; // Go through all the Membership Number Entered foreach ( $_POST as $name => $value) { // Check we only check filled out fileds if ((stristr($name,'membership')) && ($value !=0 ) ) { // Check to See if Member $check_if_member=$db->query_first("SELECT MemberID, DateExpire FROM ####### WHERE MemberID = $value"); // Set up the Arrays Elements based on Membership Detials if ($check_if_member){ $membership_result[member]=$value; $membership_result[expire]=$check_if_member['DateExpire']; } else { // Not A Member Set Up $membership_result[member]=$value; $membership_result[expire]="NOT A MEMBER"; } // Build Array for Template $member_output .="<br /> Membership Number : $membership_result[member]<br />"; $member_output .="Member or Expiry : $membership_result[expire] <br />"; } } // Print the Answer to the search eval('print_output("'. fetch_template('rsoc_member_check_output') . '");'); } ?> |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|