We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22100
    • 3 Posts
    Hi
    I’m trying to get some data out of a table in modx and put it into a table on the page,
    but I got some error

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/html/modx/manager/includes/document.parser.class.inc.php(691) : eval()’d code on line 52

    Here are my code
    function dbConnect()
        {
            $link = mysql_connect('localhost', 'lyefh', '******');
            if (!$link)
                return false;
    
            return mysql_select_db('modx');
        }
    
    function min_date($strformat,$date){
    	// Delimiters may be slash, dot, or hyphen
    	$newdate=date($strformat,strtotime($date));
    	$mount = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    	$no_mount = array("Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember");
    	$s_mount = array("May", "Oct", "Dec");
    	$no_s_mount = array("Mai", "Okt", "Des");
    	$weekday = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday","Saturday","Sunday");
    	$no_weekday = array("Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag","Laurdag","Sundag");
    	$s_weekday = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
    	$no_s_weekday = array("Man","Tir","Ons","Tor","Fre","Lau","Sun");
    	$newdate = str_replace($mount,$no_mount,$newdate);
    	$newdate = str_replace($s_mount,$no_s_mount,$newdate);
    	$newdate = str_replace($weekday,$no_weekday,$newdate);
    	$newdate = str_replace($s_weekday,$no_s_weekday,$newdate);
    	return $newdate;
    }
    
    function getProgram()
        {
    	$Start_dato = date("Y-m-d");
    
    	$tableName= $modx->getFullTableName('program');
    	$sql = sprintf("SELECT * FROM $tableName WHERE felles = 1 AND dato >= '%s' ORDER BY dato ASC", $Start_dato);
    	$sql_lim = sprintf("%s LIMIT %d, %d", $sql, 0, 15);
    	$rs= $modx->db->query($sql_lim);
    	
    	$fmnd = " ";
    	$o ="<table width='350' border='0'>
                 <tr><td></td><td></td>
                 <td><h2>Program:</h2></td>
                 </tr>";
            
    	while ($row = mysql_fetch_assoc($rs)) {;
               $mnd=min_date("F",$row_ProgramRS['dato']);
               if ( $mnd != $fmnd ) { 
    	      $o .= "<tr>
    		  <td width='65' style='font-weight:bold'>" . $mnd ."</td> </tr>";
            	} 
    	      $o .="<tr>
    	          <td width='65'>" . min_date('D d',$row['dato'])."</td>
    	          <td width='55'>kl." . min_date('H:i',$row['dato']) ."</td>
        	          <td width='200'>' .  $row['kort_tekst'] ."
    	          </td>";
                  $fmnd = $mnd;
    	      $o .= "</tr>";
            }; 
    	$o .= "</table>";
    	return $o;
    }
    
     if (!dbConnect()) {
            echo 'Error connecting to database';
            exit;
        }
    
        $output = getProgram();
    return $output;
    


    olak
      • 16886
      • 40 Posts
      Hello olak,
      i think the error is here:

      OLD: while ($row = mysql_fetch_assoc($rs)) {;
      NEW: while ($row = mysql_fetch_assoc($rs)) {
      Just remove the ;
      Gretting
      LeftHanded
        I love ModX!
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        And there also looks to be an error in the quotes here (line 52):

        <td width='200'>' .  $row['kort_tekst'] ."


        should be

        <td width='200'>" .  $row['kort_tekst'] ."
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 22100
          • 3 Posts
          Hi
          I have corrected the tow errors reported but now I got error

          Fatal error: Call to a member function on a non-object in /var/www/html/modx/manager/includes/document.parser.class.inc.php(691) : eval()’d code on line 32

          The snippet are used inside the text in a document [[program]]

          olak
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            In every function you have to have

            global $modx;
            


            so it should be

            function getProgram()
                {
                    global $modx;
            	$Start_dato = date("Y-m-d");
            
            	$tableName= $modx->getFullTableName('program');
            ...
            

              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 22100
              • 3 Posts
              Hi
              Thanks allot
              That was the clue to insert global $modx; in every function

              olak
                • 7923
                • 4,213 Posts
                don’t have to be in every function, just in the functions what use $modx


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."