Is it possible to use a variable for an SQL object fetch call instead of its string name?
I am wondering if it is possible to store the field names from a table into an array then loop through another table using the previous array data as the object for the 2nd sql loop i.e. $foo->$bar, $bar being the index in the array.
I do hope you understand what I mean here, I am having trouble explaining it myself.
So over to you wonderous masters of PHP and SQL to explain how its done properly :)
// Connect to the database to gather all data pertaiing to the link in question
$assoResult = mysql_query("SELECT * FROM associate_users");
while ($assoRow = mysql_fetch_field($assoResult)) {
$resultArray[] = 开发者_开发技巧$assoRow->name;
}
// Connect to the database to gather all data pertaiing to the link in question
$assoResult = mysql_query("SELECT * FROM associate_users WHERE id='$getID'");
while ($assoRow = mysql_fetch_object($assoResult)) {
foreach ($resultArray as $row) {
$array = array(array( 1 => $assoRow->{'$row'}, 2 => $row, ),);
}
}
Thank you in advance.
EDIT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Having worked on this further the problem only lies in
foreach ($resultArray as $row) {
$array = array(array( 1 => $assoRow->$row, 2 => $row, ),);
}
I just need the loop to add to the multi-dimensional array instead of re-writing it on eacj iteration of the foreach loop.
I am hoping this is easier an explantion of my problem :)
Maybe try this?
$array[] = array(array( 1 => $assoRow->{'$row'}, 2 => $row, ),);
精彩评论