Hi there,
suttercain wrote:Thank you Laser, I appreciate your help, but the $row['comic_id'] is set, as I stated, the above code is an include that is placed in another PHP file with another mysql_query.
Trust me it's set.
If I echo $row['comic_id'] I get the result.
My apologies for jumping in, however, you are not seeing $row['comic_id'] or the $row variable in its entirety for that matter due to your $row is being set outside the scope of your vote() function.
See the spike script below.
<?php
$row = array('test');
function vote()
{
if (isset($row)) {
echo '$row is seen from local scope';
} else {
echo '$row cannot be seen from local scope';
}
}
vote(); // will return "$row cannot be seen from local scope";
?>
Here are your options:
Pass $row in as a parameter
<?php
$row = array('test');
function vote($row)
{
if (isset($row)) {
echo '$row is seen from local scope';
} else {
echo '$row cannot be seen from local scope';
}
}
vote(); // will return "$row is seen from local scope";
?>
Advantage:
Natural - you can see this later on and "follow the bouncing ball" you can see what creates row and how the votes() function accesses it.
You can read the code without really trying to hunt down where you set the $row variable and where changes have happened prior to calling your vote() function.
Disadvantage:
You will have to refactor your existing code which uses the vote() function to pass an additional parameter. - but IMO this is a small sacrifice that will save you time later on when you need to revisit your code.
Declare $row as global
<?php
$row = array('test');
function vote()
{
global $row;
if (isset($row)) {
echo '$row is seen from local scope';
} else {
echo '$row cannot be seen from local scope';
}
}
vote(); // will return "$row is seen from local scope";
?>
Advantage:
Quick fix - all you need to do is reach out to the global scope from your function and you've got it. No changes to code.
Disadvantage:
Promotes usage of global data - so if you use and/or alter the $row variable from other functions or outside of the function, when the time comes to debug, you will not know who or what changed the $row variable.
Reading this code a few weeks later on, you will have to think about what's actually happening. Where is $row coming from? What's changing $row?
HTH.
Regards,