I intend to build transaction handlers in one php program.
I have standard/common routines to read/write/select.
2 questions:
1. Do I have to declare as global all variables that will hold field-values
or, I can use an array (declared outside the function),
and declare it as global inside the function?
2. Do I have to use declarative field-names
or theres a way to store them as a reference into an array?
array scope???
Moderator: General Moderators
As Paddy, I'm not entirely sure either of what you need to do...
So a shot in the dark to demonstrate some usage (if you didn't know allready that is
):
Result:
So a shot in the dark to demonstrate some usage (if you didn't know allready that is
Code: Select all
<pre>
<?php
$array = array(
'foo',
'bar',
'something' => 'here'
);
function x() {
global $array;
$array[] = 'moo'; // append moo using def. key incr.
$array['G'] = 'lhama'; // ...and lhama, using named key.
}
print_r($array);
echo '<br>';
x();
print_r($array);
?>Code: Select all
Array
(
ї0] => foo
ї1] => bar
їsomething] => here
)
Array
(
ї0] => foo
ї1] => bar
їsomething] => here
ї2] => moo
їG] => lhama
)explanation
Can I do this? (of course syntax is uncomplete) example:
// this code is supposed to be fixed)
$fieldname1 = 'real_name' // of mysql table
...
$afields = array($fieldname1,...)
...
$value1 = "abc"
$avalues = array($value1,...)
...
$sql = "INSERT INTO `table` ($afields[1]) VALUES ($avalue[1])"
// now I can ask for values (on the screen)
// and the user types in $value1 "xyz"
// then call the function
dowrite($sql)
function dowrite($sql, $afields, $avalues){
// I don't want to pass the real names/values
// I want to pass the reference to them, so
// so when the string $sql is evaluated/executed
// program will take the values existing at that moment
// in this case "xyz"
dowrite
// this code is supposed to be fixed)
$fieldname1 = 'real_name' // of mysql table
...
$afields = array($fieldname1,...)
...
$value1 = "abc"
$avalues = array($value1,...)
...
$sql = "INSERT INTO `table` ($afields[1]) VALUES ($avalue[1])"
// now I can ask for values (on the screen)
// and the user types in $value1 "xyz"
// then call the function
dowrite($sql)
function dowrite($sql, $afields, $avalues){
// I don't want to pass the real names/values
// I want to pass the reference to them, so
// so when the string $sql is evaluated/executed
// program will take the values existing at that moment
// in this case "xyz"
dowrite
- Derfel Cadarn
- Forum Contributor
- Posts: 193
- Joined: Thu Jul 17, 2003 12:02 pm
- Location: Berlin, Germany
No changes, just making easier to read
Code: Select all
<?php
// this code is supposed to be fixed)
$fieldname1 = 'real_name' // of mysql table
...
$afields = array($fieldname1,...)
...
$value1 = "abc"
$avalues = array($value1,...)
...
$sql = "INSERT INTO `table` ($afields[1]) VALUES ($avalue[1])"
// now I can ask for values (on the screen)
// and the user types in $value1 "xyz"
// then call the function
dowrite($sql)
function dowrite($sql, $afields, $avalues){
// I don't want to pass the real names/values
// I want to pass the reference to them, so
// so when the string $sql is evaluated/executed
// program will take the values existing at that moment
// in this case "xyz"
?>