Solved

Passing an array into a function

Posted on 2014-03-04
3
222 Views
Last Modified: 2014-03-04
I'm using an odbc connection. I've got a "description" being listed and I want to document it using an ellipsis dynamic.

Here's the HTML:

 echo ">".$modellist[$i]["cermodelid"]." - ".$modellist[$i]["createdate"]." - ".$modellist[$i]["entityshortname"]." - ".$cer_modellistdescription($modellist[$i]["description"])."";

This is all sound as far as the values are concerned. The challenge comes in the context of calling my cermodellistdescription function, which I have coded like this:

  if (!function_exists('cer_modellistdescription')) {
    function cer_modellistdescription($modellist[$i]["description"]) {
        global $edb,$_SESSION;
        
        $sql_data =" 
        $position = 150;                    
        $message = $modellist[$i]["description"];                    
        $post = substr($message,$position,1);                                         
        if($post !=" ") {                    
        $length = strlen( $message );                    
        while($post !=" " && $position < $length){                    
        $i =1;                    
        $position = $position+$i;                    
        $message =$modellist[$i]["description"];                    
        $post = substr($message,$position,1);                             
        }                    
        };"
        if ($_SESSION["portaladmin"] == 1 && $_SESSION["showsql"] != "no")
            echo display_detail("cer/cer_functions.php",$sql_data);
        $result_data = odbc_exec($edb, $sql_data);
        $the_description=odbc_result($result_data, "$post");
        return $the_description;
         }  
    }

Open in new window


The error that I'm getting is: Parse error: syntax error, unexpected '[', expecting ')' in E:\inetpub\wwwroot\mytenbi\app\cer\cer_functions.php on line 245.

Line 245 being:  function cer_modellistdescription($modellist[$i]["description"]) {

What do I need to change?
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 400 total points
ID: 39903576
I think you should call your function this way:

  if (!function_exists('cer_modellistdescription')) {
    function cer_modellistdescription($description) {
        global $edb,$_SESSION;
        
        $sql_data =" 
        $position = 150;                    
        $message = $description;                    
        $post = substr($message,$position,1);                                         
        if($post !=" ") {                    
        $length = strlen( $message );                    
        while($post !=" " && $position < $length){                    
        $i =1;                    
        $position = $position+$i;                    
        $message =$description;                    
        $post = substr($message,$position,1);                             
        }                    
        };"
        if ($_SESSION["portaladmin"] == 1 && $_SESSION["showsql"] != "no")
            echo display_detail("cer/cer_functions.php",$sql_data);
        $result_data = odbc_exec($edb, $sql_data);
        $the_description=odbc_result($result_data, "$post");
        return $the_description;
         }  
    }
                                  

Open in new window



and call it this way

cer_modellistdescription($modellist[$i]["description"]);
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 100 total points
ID: 39903629
Agree with marqusG.  The function definition uses a placeholder variable.  PHP.net tells how to do this.
http://php.net/language.functions.php
http://php.net/manual/en/functions.user-defined.php
http://php.net/manual/en/functions.arguments.php

Do not write global $_SESSION -- it's already a global and that sort of thing is a code smell that kind of signals to the world that you don't understand variable scope.
0
 

Author Comment

by:brucegust
ID: 39903782
Thanks! This will work, but I'm wondering if I could try to do my heavy lifting on the store procedure side. If you've got some thoughts, head out to http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28379937.html.

Thanks, again!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question