Parse error: syntax error, unexpected T_SL in C:\AppServ\www\graphtest.php on line 15

Posted on 2009-02-22
Last Modified: 2013-12-13
$sql = <<<EOS   this have problem......but what is it?
also $conn->Connect('localhost', 'root', '1234567', 'zend');

'zend ' what is this filed i should input?
i use Jpgraph ~ php4




if (USE_DB) { 

    // establish a connect to the database 

    $conn = &ADONewConnection('mysql'); 

    $conn->Connect('localhost', 'root', '1234567', 'zend'); 


    // make an sql statement to retrieve the data you want 

   $sql = <<<EOS 

    SELECT dt, 

        MONTHNAME(dt) AS mon, 




    FROM data 

    WHERE dt >= '2002-01-01' 

        AND dt < '2003-01-01' 

    ORDER BY dt ASC 


    // create a result set by executing your sql over the connection 

    $rs = $conn->Execute(trim($sql)); 

    // iterate over the result set and create $data arrays 

    while ($rs && !$rs->EOF) { 

        $row = $rs->fields; 

        $labelx[] = substr($row['mon'],0,3); 

        $data['plan'][] = $row['plan']; 

        $data['actual'][] = $row['actual']; 

        $data['forecast'][] = $row['forecast']; 



} else { // USE_DB false 

    $data['plan'] = array (  

            11.5, 12, 12, 13.5, 10, 9.5,  

            11, 12, 12, 11, 13, 12.5 ); 

    $data['actual'] = array(  

            12, 14, 14.5, 13, 9, 4,  

            0, 0, 0, 0, 0, 0 ); 

    $data['forecast'] = array (  

            0, 0, 0, 0, 0, 10,  

            12, 14, 13, 10, 11, 13 ); 

    for($i = 0; $i < count($data['actual']); $i++) { 

        $labelx[] = strftime('%b',  

                mktime(0, 0, 0, $i+1, 1, date('Y'))); 



// create the "good" and "bad" series for our red/green look 

for($i = 0; $i < count($data['actual']); $i++) { 

    if ($data['actual'][$i] >= $data['plan'][$i]  

        || $data['forecast'][$i] >= $data['plan'][$i]) { 

        $data['good'][$i] = $data['actual'][$i]; 

        $data['bad'][$i] = 0; 

    } else { 

        $data['good'][$i] = 0; 

        $data['bad'][$i] = $data['actual'][$i]; 



// set title and name for the chart 

$title = date('Y').' Plan vs Actual & Forecast'; 

$graph_name = 'chart.png'; 


* JpGraph - Step 1 

* Create the graph object and set general parameters 


// set general graph details 

$graph = new graph(450, 300, $graph_name, 0, false); 

//    margins, background color, scale and shadow for the whole graph 

$graph->img->SetMargin(50, 30, 30, 80); 




//    set the title and font 


$graph->title->SetFont(FF_VERDANA, FS_BOLD, 14); 

//    set the y-axis and title it 


$graph->yaxis->title->Set('Units in Thousands'); 

$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD); 

//    set the x-axis, labels and title it 


$graph->xaxis->SetFont(FF_VERDANA, FS_NORMAL, 8); 


//    set the graph title and font 


$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD); 


* JpGraph - Step 2 

* Set the individual plot details 


// line1 is the plan data line, green, thick and marked with circles 

$line1 = new LinePlot($data['plan']); 






// bar1 is the green bars for actual or forecast above plan 

$bar1 = new BarPlot($data['good']); 




$bar1->SetLegend('Actual above Plan'); 

// bar2 is the red bars for actual and forecast below plan 

$bar2 = new BarPlot($data['bad']); 




$bar2->SetLegend('Actual below Plan'); 

// bar3 is the gray bars for forecast data 

$bar3 = new BarPlot($data['forecast']); 






* JpGraph - Step 3 

* Finalize and output the graph 


// set legend details 


$graph->legend->Pos(0.52, 0.85, 'center'); 

// add the graphs bottom to top 





// output the graph to cache 


$page_title = 'Zend Graphing Tutorial'; 

/*    another example not covered in the tutorial, 

    output the data series values 

    into a table below the graph 


for($i = 0; $i < count($data['actual']); $i++) { 

    $row_head .= '<th>'.$labelx[$i].'</th>'; 

    $row_plan .= '<td>'.number_format($data['plan'][$i], 1).'</td>'; 

    $row_act  .= '<td>'.number_format($data['actual'][$i], 1).'</td>'; 

    $row_fcst .= '<td>'.number_format($data['forecast'][$i], 1).'</td>'; 


print <<<EOS 






<div style="text-align: center"> 


<img src="{$jpgcache}{$graph_name}" /> 

<p /> 

<table border="1" cellpadding="5" cellspacing="0"> 

<tr align="center"><th>Data</th>$row_head</tr> 

<tr align="right"><td><b>Plan</b></td>$row_plan</tr> 

<tr align="right"><td><b>Actual</b></td>$row_act</tr> 

<tr align="right"><td><b>Forecast</b></td>$row_fcst</tr> 







Open in new window

Question by:ftpphptest1
    LVL 14

    Expert Comment

    by:Ionut A. Tudor
    for your first question it is a heredoc syntax EOF not EOS
    $sql = <<<EOF
        SELECT dt,
            MONTHNAME(dt) AS mon,
        FROM data
        WHERE dt >= '2002-01-01'
            AND dt < '2003-01-01'
        ORDER BY dt ASC
    this is the correct use, with any spaces after EOF
    For your second question `zend` is your database name.
    Hope this helps
    LVL 34

    Expert Comment

    by:Terry Woods
    The error is caused by the space character after the EOS on this line:

       $sql = <<<EOS 

    Open in new window

    LVL 8

    Expert Comment

    i belive the guys here have answered your first Q ... but i have a comment on the second Q

    the zend value here called new_link
    "If a second call is made to mysql_connect()        with the same arguments, no new link will be established, but        instead, the link identifier of the already opened link will be        returned. The new_link  parameter modifies this         behavior and makes mysql_connect() always open         a new link, even if mysql_connect() was called         before with the same parameters.        In SQL safe mode, this parameter is ignored.       "

    unless your connect function has different structure
    LVL 8

    Accepted Solution

    also i tried the attached code and i got

    Invalid query: No database selected

    mysql_connect('localhost','root','root','test') or die('Could not connect: ' . mysql_error());
    $res = mysql_query('select * from users') or die('Invalid query: ' . mysql_error());

    Open in new window


    Author Comment

    what is the meaning ?
    as i find that there many sytax error...
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    LVL 8

    Expert Comment

    we need to see the function connect() code

    Author Comment

    do u have any other example showing data in MySQL to the line chart ?

    differnet element vs time line chart
    LVL 8

    Expert Comment

    if you want to make graph   ... there is a lot of tools to make graphs ... but the important thing to prepare the data in format to be ready to be plotted

    Author Comment

    o ic~~~so i need some example to show how to link php with mySQL to show data in chart
    LVL 14

    Expert Comment

    by:Ionut A. Tudor
    You can open new question for that, i think this question with that error T_SL has been solved. Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    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.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now