We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13710
    • 14 Posts
    Hey MOD X

    I’ve wrote several snippets to use within modx with Dreamweaver.
    Nothing special. They connect to a separate database and get information relating to the article they are currently viewing.

    they all work when it only one snippet in use.
    but when i try to run two of my snippets on the same page, the page won’t run.

    any ideas on what i should do
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Some code might help; use the # button in the forum editor’s toolbar to enclose your code and make it more readable.
        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
        • 13710
        • 14 Posts
        FYI i use MODX for a tube site.
        this snippet connects to a database and gets the top movies, recently watch movies and the movies i think people should see.
        it works just fine.

        <?php
        require_once('Connections/****.php'); 
        require_once('Connections/****.php'); 
        
        if (!function_exists("GetSQLValueString")) {
        function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
        {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
        
        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
        
        switch ($theType) {
        case "text":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;    
        case "long":
        case "int":
        $theValue = ($theValue != "") ? intval($theValue) : "NULL";
        break;
        case "double":
        $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
        break;
        case "date":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;
        case "defined":
        $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
        break;
        }
        return $theValue;
        }
        }
        
        mysql_select_db($database_wxyz, $wxyz);
        $query_Recordset1 = "SELECT pageurl, COUNT(pageurl) as numvotes FROM hitus GROUP BY pageurl ORDER BY numvotes DESC LIMIT 10";
        $Recordset1 = mysql_query($query_Recordset1, $wxyz) or die(mysql_error());
        $row_Recordset1 = mysql_fetch_assoc($Recordset1);
        $totalRows_Recordset1 = mysql_num_rows($Recordset1);
        
        mysql_select_db($database_wxyz, $wxyz);
        $query_Recordset3 = "SELECT * FROM hitus ORDER BY hitus.ts DESC LIMIT 10";
        $Recordset3 = mysql_query($query_Recordset3, $wxyz) or die(mysql_error());
        $row_Recordset3 = mysql_fetch_assoc($Recordset3);
        $totalRows_Recordset3 = mysql_num_rows($Recordset3);
        
        
        echo "<div align='center'><br>";
        
        echo "     <span style='font-weight: bold'><a href='[~965~]' title='Top Flixx'>Top Flixx</a>  </span></div>"; 
        
        do { 
        echo "  <table width='100%' border='0'>";
        echo "   <tr>";
        echo "      <td>"; 
        
        
        $o = $row_Recordset1['pageurl'] ;
        mysql_select_db($database_abcd, $abcd);
        $query_Recordset2 = "SELECT * FROM modx_site_content WHERE modx_site_content.id = '$o'";
        $Recordset2 = mysql_query($query_Recordset2, $abcd) or die(mysql_error());
        $row_Recordset2 = mysql_fetch_assoc($Recordset2);
        $totalRows_Recordset2 = mysql_num_rows($Recordset2);
        
        
        
        
        $first = $row_Recordset2['id'];
        $first2 = $row_Recordset2['pagetitle'];
        echo"   <a href=\"index.php?id=$first\">  $first2 </a></td>";
        
        echo"
        </tr>
        </table>"; 
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); 
        
        echo" <br>
        
        <div align='center'><br>
        
        <span style='font-weight: bold'>Recently Viewed  </span></div>";
        do { 
        echo "  <table width='100%' border='0'>";
        echo "   <tr>";
        echo "      <td>"; 
        
        
        $o = $row_Recordset3['pageurl'] ;
        mysql_select_db($database_abcd, $abcd);
        $query_Recordset4 = "SELECT * FROM modx_site_content WHERE modx_site_content.id = '$o'";
        $Recordset4 = mysql_query($query_Recordset4, $abcd) or die(mysql_error());
        $row_Recordset4 = mysql_fetch_assoc($Recordset4);
        $totalRows_Recordset24 = mysql_num_rows($Recordset4);
        
        
        
        
        $sec = $row_Recordset4['id'];
        $sec2 = $row_Recordset4['pagetitle'];
        echo"   <a href=\"index.php?id=$sec\">  $sec2 </a></td>";
        
        echo"
        </tr>
        </table>"; 
        } while ($row_Recordset3 = mysql_fetch_assoc($Recordset3)); 
        
        
        mysql_select_db($database_wxyz, $wxyz);
        $query_Recordset5 = "SELECT * FROM favorites ORDER BY favorites.idx DESC LIMIT 5";
        $Recordset5 = mysql_query($query_Recordset5, $wxyz) or die(mysql_error());
        $row_Recordset5 = mysql_fetch_assoc($Recordset5);
        $totalRows_Recordset5 = mysql_num_rows($Recordset5);
        
        //////////////////
        
        echo" <br>
        
        <div align='center'><br>
        
        <span style='font-weight: bold'>ModelFlixx Favorites  </span></div>";
        do { 
        echo "  <table width='100%' border='0'>";
        echo "   <tr>";
        echo "      <td>"; 
        
        
        $x = $row_Recordset5['id'] ;
        mysql_select_db($database_wxyz, $wxyz);
        $query_Recordset6 = "SELECT * FROM modx_site_content WHERE modx_site_content.id = '$x'";
        $Recordset6 = mysql_query($query_Recordset6, $wxyz) or die(mysql_error());
        $row_Recordset6 = mysql_fetch_assoc($Recordset6);
        $totalRows_Recordset24 = mysql_num_rows($Recordset6);
        
        
        
        
        $secc = $row_Recordset6['id'];
        $secc2 = $row_Recordset6['pagetitle'];
        echo"   <a href=\"index.php?id=$secc\">  $secc2 </a></td>";
        
        echo"
        </tr>
        </table>"; 
        } while ($row_Recordset5 = mysql_fetch_assoc($Recordset5)); 
        
        
        
        ?>
        ?>


        I want to add this snippet to the page.
        the code will display how many times a movie was viewed.


        <?php
        require_once('Connections/****.php'); ?>
        <?php
        $ips = $_GET["id"];
        mysql_select_db($database_abcd, $abcd);
        $query_Recordset1 = "SELECT * FROM hitus WHERE hitus.pageurl = '$ips'";
        $Recordset1 = mysql_query($query_Recordset1, $abcd) or die(mysql_error());
        $row_Recordset1 = mysql_fetch_assoc($Recordset1);
        $totalRows_Recordset1 = mysql_num_rows($Recordset1);
        
        echo $totalRows_Recordset1; 
        echo ' Views';
        ?>
        ?>
        


        I get this error:
        « MODx Parse Error »
        MODx encountered the following error while attempting to parse the requested resource:
        « PHP Parse Error »
         
        PHP error debug
          Error: 	mysql_select_db(): supplied argument is not a valid MySQL-Link resource	 
          Error type/ Nr.: 	Warning - 2	 
          File: 	/home/content/j/a/z/jazzmatazz2005/html/manager/includes/document.parser.class.inc.php(770) : eval()'d code	 
          Line: 	4	 
         
        Parser timing
          MySQL: 	0.0483 s	(118 Requests)
          PHP: 	0.6698 s	 
          Total: 	0.7181 s


        how can i get both snippets to run on the same page?
          • 10487 MODX Staff
          • 1,535 Posts
          Try using require() instead of require_once() - I’m presuming that your database connection is initiated in the connection file.
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 13710
            • 14 Posts
            Thanks Garryn.

            Problem Solved.

            This discussion is closed to further replies. Keep calm and carry on.