I have the following code;_
$sql = "select * from text where id = '$id' "; $row = fetch_row_row( $sql, $db ); $img_loc = $row["img_loc"]; $text_type = $row["text_type"]; $seq = $row["seq"]; $rec_type = $row["rec_type"]; $section = $row["section"]; $code = $row["code"]; $repeat = $row["repeat"]; $description = $row["description"] ); $text = $row["text"] );
Was wondering if there was a clever way of doing this with foreach on $row. something like
foreach( $row as $index => value ) { create_var( $index, $value ); }
So the question is is there a function like create_var which takes a string and a value and creates a variable?
I think extract() is what you're after. Just note that the quickest way to do things isn't always the best.
Is $description going to be shown to the users? How are you protecting it so that it doesn't contain HTML/JavaScript code? Is any of this going into form elements? How are you preparing it so that a double/single quote doesn't end the form element?
Just pointing out that although you can quickly create the variables you're after with extract(), there may still be other things you should do before you use them.
Also, why are you wasting processing time creating $text instead of just using $row['text'] in whatever output you have? It's a few more characters to type, but it takes away one level of possible confusion when you come back to this code later.
Just my $0.02.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php