Solved

Passing an array into a function

Posted on 2014-03-04
3
219 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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