PHPBuilder - Variable Variables Page 3



RSS Twitter
Articles Tricks And Hacks

Variable Variables - Page 3

by: Robert Berkowitz
|
September 28, 2000


<?php

//This loops through all the records that have been displayed on the page.

for ($index 0$index <= $counter$index++) {

    
    
/*
    This part sets a variable with the names we created in the first section.  
    We start with 0 and go until the number saved in the $index_count variable.
    */ 
    
    
$varSubmissionID 'SubmissionID'.$index;
    
$varPostedBy 'PostedBy'.$index;
    
$varLink 'Link'.$index;
    
$varDescription 'Description'.$index;
    
$varApproved 'Approved'.$index;

    
    
/*
    This is the variable variable section.  We take the value that was assigned 
    to each name variable.  For example the first time through the loop we are 
    at the record assigned with SubmissionID0.  The value given to SubmissionID0 
    is set from the first section.  We access this value by taking the variable 
    variable of what SubmissionID0 is.
    */

    
$SubmissionIDvalue = $$varSubmissionID;
    
$PostedByvalue = $$varPostedBy;
    
$Linkvalue = $$varLink;
    
$Descriptionvalue = $$varDescription;
    
$Approvedvalue = $$varApproved;


    
//Update the database

    
$sql "UPDATE submissions SET PostedBy='$PostedByvalue',Link='$Linkvalue',".
        
"Description='$Descriptionvalue' WHERE SubmissionID=$SubmissionIDvalue'";
    
$result mysql_query($sql);


    
//If the link was marked approved set the value of the Approved field

    
if ($Approvedvalue == '-1') {
        
$sql "UPDATE submissions SET Approved='-1' WHERE SubmissionID=$SubmissionIDvalue";
        
$result mysql_query($sql);
    }

}

?>
I hope this has helped you to understand the basics of variable variables and given you some ideas of how to use them in future projects. They were pretty confusing to me at first, but once you get the basic understanding of how variable variables work they're a piece of cake. Let me know if you have any other questions.
--Robert

« Previous Page
1
|
2
|
3

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Robert Berkowitz

Comment:



Comment:

(Maximum characters: 1200). You have characters left.