Question

How can i modify the echo to allow the substr in a curly bracket. I have added other columns from the table to the array but I cannot seem to fetch the first 40 characters using the substr in an echo.

$query = "SELECT * FROM events";

$events = mysql_query($query,$dbc);

while ($eventlist = mysql_fetch_array($events))
{

 echo "<div id=\"container7\">
 <div id=\"contenttopcolumn\">                                 

                        </div>

                    </div>
<div id=\"container7\">
<div id=\"contentbottomcolumn\"> 

<h3> {$eventlist['title']} | {$eventlist['location']}</h3></a>
{$eventlist['date']} 
<p>
{$eventlist['date']}

 substr($eventlist['description'], 0, 40)





 </p>
 </div>
                        </div>




 ";
Was it helpful?

Solution

You have to close the string with something like ". ."

Like this:

 echo " <div id=\"container7\">
            <div id=\"contenttopcolumn\">                                 
            </div>
        </div>
        <div id=\"container7\">
            <div id=\"contentbottomcolumn\"> 
                <h3> {$eventlist['title']} | {$eventlist['location']}</h3></a>
                {$eventlist['date']} 
                <p>
                    {$eventlist['date']}
                        ".substr($eventlist['description'], 0, 40)."
                </p>
            </div>
        </div> 
 ";

Should also be noted that your HTML is invalid, closing </a> with no opening anchor tag

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top