Jump to content

[SOLVED] function name as array value?


blueman378

Recommended Posts

hi guys,

i have this code,

<?php
function $row[cName](){
global $database;
    $q = "SELECT * FROM " . Games . "
          WHERE category='$row[cName]'
          ORDER BY `gName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error());
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
if( $num_rows == 0 ){
      return '<font size="2">Games not found!</font>';
    }
        /* Display table contents */
    $content = "$num_rows";
    }
    return $content;


// You can
echo $row[cName]();
?>

 

btw

$row[cName]

is defined in a prior sql statment,

 

anyway my question is is it possible to have the function name as the array results

 

a thing it might be useful to know this code is included in this:

    $q = "SELECT cName FROM " . gsubcat . "
          ORDER BY `cName` ASC
         ";   
    $result = $database->query($q) or die("Error: " . mysql_error());
    /* Error occurred, return given name by default */
    $num_rows = mysql_numrows($result);
    if( $num_rows == 0 ){
      return 'Cats not found!';
    } ?><table border="1" cellpadding="3" cellspacing="0" ><tr><td><b>Name</b></td><td><b>Games Assigned</b></td><td><b>Actions</b></td> </tr><?php
   while( $row = mysql_fetch_assoc($result) ) {
   echo '<tr><td>';
    echo $row[cName]  ?></td>
<td><?php include("gamecount.php"); ?>
 </td> <?php echo '
<td><a href="catprocess.php$action=Delete&$cat=' . $row['cName'] . '">
<img src="../images/Delete.png" alt="Delete" Title="Delete"></a><a href="catprocess.php$action=Browse&$cat=' . $row['cName'] . '">
<img src="../images/Browse.png" alt="Browse" Title="Browse"></a></td></tr>';
    }

?></table>
<br>
<br>
<?php 
//cat form end

?>

 

the error i get is

Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in C:\wamp\www\admin\gamecount.php on line 2

which i gather its saying it was expecting a solid value rather than a variable

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.