?
Solved

Passing an array into a function

Posted on 2014-03-04
3
Medium Priority
?
225 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 1600 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
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.
Suggested Courses

764 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