Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to load a file that's normally shown with Javascript with PHP?

I have to show a music sheets and I use Open Sheet Music Display for that. There is JavaScript code used to display the sheet. Now I want to load an MXML file from my database.
Normally this was the code that it needed to display it:

      <script src="../scripts/opensheetmusicdisplay.min.js"></script>
        <div id="osmdCanvas"></div>
        <script >
        var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay('osmdCanvas');
            osmd.setOptions({
            backend: 'svg',
            drawTitle: true,
            });

        osmd.load('../xml/Band_Of_Brothers.musicxml').then(function () {
        osmd.render();
        });
        </script>

But now I try to do it with my database item I replaced the normal location to that database element in the way shown below. But it doesn’t work anymore. How can I solve it?

        <script src="../scripts/opensheetmusicdisplay.min.js"></script>
            <div id="osmdCanvas"></div>
            <script >
                <?php
                $query = 'SELECT `sheets_xml` FROM `imslp_sheets` WHERE 1';
                $result = $conn->query($query);
                if ($result->num_rows > 0) {
                    while ($row = $result->fetch_assoc()) {
                        $thisXmlSheet = $row['sheets_xml'];
                    }
                }
                echo "
            var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay('osmdCanvas');
                osmd.setOptions({
                backend: 'svg',
                drawTitle: true,
                });

            osmd.load('$thisXmlSheet').then(function () {
            osmd.render();
            });";
                ?>
        </script>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think it is the path problem.

So, please change using the following instead:

<?php
$query = 'SELECT `sheets_xml` FROM `imslp_sheets` WHERE 1';
$result = $conn->query($query);

if ($result->num_rows > 0) {
  while ($row = $result->fetch_assoc()) {
    $thisXmlSheet = $row['sheets_xml'];
  }
}
?>
 <script src="../scripts/opensheetmusicdisplay.min.js"></script>
        <div id="osmdCanvas"></div>
        <script >
        var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay('osmdCanvas');
            osmd.setOptions({
            backend: 'svg',
            drawTitle: true,
            });

        osmd.load('../xml/<?php echo $thisXmlSheet; ?>').then(function () {
        osmd.render();
        });
        </script>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading