• Resolved wolfshui

    (@wolfshui)


    I really am not sure what I am doing. I know enough coding to get myself in trouble.

    What I am trying to do is create a page that my users can go to and print off a PDF that is filled out with a lot of data from a Mysql Database. I am having a problem writing the code in the code manager though and I want to know if I am missing something, or if I am trying to do something with this that it is not meant to do.

    (In the end it should look something like this: https://content.instructables.com/ORIG/F32/Y0FV/J8F5Q3W5/F32Y0FVJ8F5Q3W5.png?auto=webp&frame=1&width=1024&height=1024&fit=bounds&md=5a45ebe2850f9ab8d04792009d63d6a5)

    Specifically, you will notice that I have to put “\” in the code at places where is normally should not go. why this is working, I have no clue. I assume I am confusing the system into doing what I want it to do. I have no clue if this is the correct way to achieve what I am looking for or not.

    Here is a copy of my code with some info scrubbed.

    
    

    <?php

    $servername = “Removed”;
    $username = “Removed”;
    $password = “Removed”;
    $dbname = “Removed”;
    $current_user = wp_get_current_user();

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die(“Connection failed: ” . $conn->connect_error);
    }

    //$sql = “SELECT * FROM LARP_Characters WHERE Username = ‘”.$current_user->user_login.”‘”;
    //$sql = “SELECT * FROM LARP_Characters”;
    $sql = “SELECT * FROM LARP_Characters WHERE Status = ‘Active’ ORDER BY ‘Name'”;
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {

    echo “<form>”;
    echo “Choose a Character: “;
    echo “<select name=’Character_Name’>”;

    // output data of each row
    while($row = $result->fetch_assoc()) {
    $selected = ($row[‘Character_Name’] == $_GET[‘Character_Name’]) ? “selected” : “”;
    echo “<option value='”.$row[‘Character_Name’].”‘ $selected>”.$row[‘Character_Name’].”</option>”;
    }

    echo “</select><br>”;
    echo “<br /><input type=’submit’ value=’Load Character Sheet’><br><br>”;
    echo “</form>”;
    } else {
    echo “0 results ; $sql ; “.json_encode($current_user);
    }

    if ($_GET[‘Character_Name’]) {
    //echo $_GET[‘Character_Name’];

    //$sql = “SELECT * FROM LARP_Characters WHERE Character_Name = ‘”.$_GET[‘Character_Name’].”‘”;
    //$sql = “SELECT * FROM LARP_Characters WHERE Username = ‘”.$current_user->user_login.”‘ AND Character_Name = ‘”.$_GET[‘Character_Name’].”‘”;
    //$sql = “SELECT * FROM LARP_Characters WHERE Approved = ‘Yes'”;
    $sql = “SELECT * FROM LARP_Characters WHERE Status = ‘Active’ ORDER BY ‘Name’ ASC”;
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    //echo “<div class=\”character-sheet\”><div style=\”overflow-x:auto\”>
    echo “<div class=\”character-sheet\”><div style=\”page-break-before:always ; margin: 0 auto ; width:100% ; \”>
    <table border=\”0\”>
    <tbody>
    <tr>
    <td colspan=\”1\”>Player: </td>
    <td colspan=\”3\”>” . $row[“Name”]. “</td>
    <td colspan=\”1\”>Name: </td>
    <td colspan=\”3\”>” . $row[“Character_Name”]. “</td>
    </tr>
    <tr>
    <td colspan=\”4\”>Occupation: ” . $row[“Occupation”]. ” – ” . $row[“Monthly_Gain”]. “</td>
    <td colspan=\”2\”>Mortality? </td>
    <td colspan=\”2\”>” . $row[“Mortality”]. ” – ” . $row[“Mortality_Rating”]. “</td>
    </tr>
    <tr>
    <td colspan=\”2\”><div style=\”text-align:center\”>Currency</div></td>
    <td colspan=\”1\”><div style=\”text-align:right\”>Copper Pieces: </div></td>
    <td colspan=\”1\”>” . $row[“CP”]. “</td>
    <td colspan=\”1\”><div style=\”text-align:right\”>Silver Pieces: </div></td>
    <td colspan=\”1\”>” . $row[“SP”]. “</td>
    <td colspan=\”1\”><div style=\”text-align:right\”>Gold Pieces: </div></td>
    <td colspan=\”1\”>” . $row[“GP”]. “</td>
    </tr>
    <tr>
    <td colspan=\”1\”><div style=\”text-align:right\”>Ammo: </div></td>
    <td colspan=\”1\”>” . $row[“Ammo”]. “</td>
    <td colspan=\”1\”><div style=\”text-align:right\”>Arrows: </div></td>
    <td colspan=\”1\”>” . $row[“Arrows”]. “</td>
    <td colspan=\”1\”><div style=\”text-align:right\”>Locks: </div></td>
    <td colspan=\”1\”>” . $row[“Locks”]. “</td>
    <td colspan=\”1\”><div style=\”text-align:right\”>Ailment: </div></td>
    <td colspan=\”1\”>” . $row[“Ailments”]. “</td>
    </tr>
    <tr>
    <td colspan=\”2\”><div style=\”text-align:right\”>Other Possessions: </div></td>
    <td colspan=\”6\”>” . $row[“Other_Items”]. “</td>
    </tr>
    </tr>
    <td colspan=\”8\”>
    <table border=\”1\” width=\”100%\”>
    <tbody>
    <tr>
    <td></td>
    <td><div style=\”font-weight: bold\”>Animal</div></td>
    <td><div style=\”font-weight: bold\”>Chemical</div></td>
    <td><div style=\”font-weight: bold\”>Plant</div></td>
    <td><div style=\”font-weight: bold\”>Ore</div></td>
    <td><div style=\”font-weight: bold\”>Stone</div></td>
    <td><div style=\”font-weight: bold\”>Magic</div></td>
    <td><div style=\”font-weight: bold\”>Technology</div></td>
    </tr>
    <tr>
    <td><div style=\”font-weight: bold\”>Common</div></td>
    <td>” . $row[“Common_Animal”]. ” </td>
    <td>” . $row[“Common_Chemical”]. ” </td>
    <td>” . $row[“Common_Plant”]. ” </td>
    <td>” . $row[“Common_Ore”]. ” </td>
    <td>” . $row[“Common_Stone”]. ” </td>
    <td>” . $row[“Common_Magic”]. ” </td>
    <td>” . $row[“Common_Technology”]. ” </td>
    </tr>
    <tr>
    <td><div style=\”font-weight: bold\”>Scarce</div></td>
    <td>” . $row[“Scarce_Animal”]. ” </td>
    <td>” . $row[“Scarce_Chemical”]. ” </td>
    <td>” . $row[“Scarce_Plant”]. ” </td>
    <td>” . $row[“Scarce_Ore”]. ” </td>
    <td>” . $row[“Scarce_Stone”]. ” </td>
    <td>” . $row[“Scarce_Magic”]. ” </td>
    <td>” . $row[“Scarce_Technology”]. ” </td>
    </tr>
    <tr>
    <td><div style=\”font-weight: bold\”>Rare</div></td>
    <td>” . $row[“Rare_Animal”]. ” </td>
    <td>” . $row[“Rare_Chemical”]. ” </td>
    <td>” . $row[“Rare_Plant”]. ” </td>
    <td>” . $row[“Rare_Ore”]. ” </td>
    <td>” . $row[“Rare_Stone”]. ” </td>
    <td>” . $row[“Rare_Magic”]. ” </td>
    <td>” . $row[“Rare_Technology”]. ” </td>
    </tr>
    </tbody>
    </table>
    </td>
    </tr>
    <tr>
    <td colspan=\”8\”>
    ____________________________________________________________________________________________________________________________________________________
    </td>
    </tr>
    <tr>
    <td colspan=\”8\”>
    <table border=\”1\” width=\”100%\”>
    <tbody>
    <tr>
    <td colspan=\”8\”><div style=\”text-align:Center\”>Abilities</div></td>
    </tr>
    <tr>
    <td>Background Ability: </td>
    <td colspan=\”7\”>” . $row[“BGA”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“BGA_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 1: </td>
    <td colspan=\”7\”>” . $row[“A1”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A1_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 2: </td>
    <td colspan=\”7\”>” . $row[“A2”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A2_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 3: </td>
    <td colspan=\”7\”>” . $row[“A3”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A3_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 4: </td>
    <td colspan=\”7\”>” . $row[“A4”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A4_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 5: </td>
    <td colspan=\”7\”>” . $row[“A5”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A5_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 6: </td>
    <td colspan=\”7\”>” . $row[“A6”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A6_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 7: </td>
    <td colspan=\”7\”>” . $row[“A7”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A7_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 8: </td>
    <td colspan=\”7\”>” . $row[“A8”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A8_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 9: </td>
    <td colspan=\”7\”>” . $row[“A9”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A9_Notes”]. “</td>
    </tr>
    <tr>
    <td>Ability 10: </td>
    <td colspan=\”7\”>” . $row[“A10”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>Upgrades: ” . $row[“A10_Notes”]. “</td>
    </tr>
    </tbody>
    </table>
    </td>
    </tbody>
    </table></div></div>
    <br> <br>

    <div class=\”character-sheet\”><div style=\”page-break-before:always ; margin: 0 auto ; width:100% ; \”>
    <table border=\”5\” width=\”100%\”>
    <tbody>
    <tr>
    <td colspan=\”8\”>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Known Recipies</div>
    </td>
    </tr>
    <tr>
    <td colspan=\”8\”>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Recipes You Have Learned</div>
    </td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP1”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP2”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP3”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP4”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP5”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP6”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP7”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP8”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP9”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP10”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP11”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP12”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP13”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP14”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP15”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP16”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP17”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP18”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP19”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>” . $row[“RP20”]. “</td>
    </tr>
    <tr>
    <td colspan=\”8\”>
    <div style=\”background-color: lightgrey; text-align: Center;\”>End of Event Check-In</div>
    </td>
    </tr>
    <tr>
    <td colspan=\”1\”>
    <div style=\”background-color: lightgrey; text-align: right;\”>Refered By:</div>
    </td>
    <td colspan=\”3\”>________________________________________</td>
    <td colspan=\”1\”>
    <div style=\”background-color: lightgrey; text-align: right;\”>Event Name:</div>
    </td>
    <td colspan=\”3\”>_________________________________________________________</td>
    </tr>
    <tr>
    <td colspan=\”2\”>
    <div style=\”background-color: lightgrey; text-align: right;\”>Event Number<br></div>
    </td>
    <td colspan=\”2\”>
    <div>#1 <input type=\”checkbox\”> | #2 <input type=\”checkbox\”> | #3+ <input type=\”checkbox\”></div>
    </td>
    <td colspan=\”1\”>
    <div style=\”background-color: lightgrey; text-align: right;\”>Date:</div>
    </td>
    <td colspan=\”3\”>_________________________________________________________</td>
    </tr>
    <tr>
    <td colspan=\”1\”>
    <div style=\”background-color: lightgrey; text-align: Right;\”>Mortality<br></div>
    </td>
    <td colspan=\”1\”>__________</td>
    <td colspan=\”1\”>Unlearned Recipies</td>
    <td colspan=\”5\”>__________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Copper<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”1\”>Artifacts</td>
    <td colspan=\”5\”>__________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Silver<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”6\”>___________________________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Gold<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”1\”>Crafted Itmes</td>
    <td colspan=\”5\”>__________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Arrows<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”6\”>___________________________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Ammo<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”1\”>Other Items</td>
    <td colspan=\”5\”>__________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Locks<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”6\”>___________________________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Ailment<br></div>
    </td>
    <td>__________</td>
    <td colspan=\”1\”>Abilities Trained</td>
    <td colspan=\”5\”>__________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: right;\”>Ailment Lvl</div>
    </td>
    <td>__________</td>
    <td colspan=\”1\”>CSP (GM Only)</td>
    <td colspan=\”5\”>__________________________________________________________________________________________________</td>
    </tr>
    <tr>
    <td> </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Animal</div>
    </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Chemical</div>
    </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Plant</div>
    </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Ore</div>
    </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Stone</div>
    </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Magic</div>
    </td>
    <td>
    <div style=\”background-color: lightgrey; text-align: Center;\”>Technology</div>
    </td>
    </tr>
    <tr border=\”5px\”>
    <td>
    <div style=\”background-color: lightgrey; text-align: Right;\”>Common<br></div>
    </td>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: Right;\”>Scarce<br></div>
    </td>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: Right;\”>Rare<br></div>
    </td>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    <td><div style=\”text-align: Center;\”>__________</td></div>
    </tr>
    <tr>
    <td>
    <div style=\”background-color: lightgrey; text-align: Right;\”>Quest Mats:</div>
    </td>
    <td colspan=\”7\”>____________________________________________________________________________________________________________________________________
    </td>
    </tr>
    </tbody>
    </table></div></div>
    <br> <br>

    “;
    }
    } else {
    echo “Unable to Load Character Details”;
    }
    }

    $conn->close();
    ?>`
    `

    If anyone is able to tell me an easier or better way to do what I am trying to do, please share it with me.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @wolfshui,

    Sorry for the late reply! That’s a lot of code. ??

    The reason why you need to add the \ in front of the double quotes is because the double quotes are added to a string surrounded by double quotes. The simplest way to solve this issue is to add single quotes instead of double quotes. But for your use case I would advice to use the heredoc format. That makes your code much more readable.

    Does this help?

    Thanks,
    Peter

    Thread Starter wolfshui

    (@wolfshui)

    It gives me a direction to research!

    One follow up to this: Is there a way to utilize something like the FPDF library through the code manager?

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @wolfshui,

    That’s an interesting question! ?? THX

    Yes, you can! I created a hello world example for you. You can find and download it here:
    https://code-manager.com/code/?wpda_search_column_code_name=fpdf

    Please be aware that this code is execute from the back-end and therefor requires a premium license. If you can open the FPDF output in a new tab or window, you should be able to execute it from a shortcode. Maybe you can share such a solution if you find a way… ??

    Hope this helps,
    Peter

    Thread Starter wolfshui

    (@wolfshui)

    Thanks!

    Thread Starter wolfshui

    (@wolfshui)

    Ok, I am stuck. I followed your instructions, but all I am getting on the test URL is “0”.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi @wolfshui,

    I guess the problem is in the code block type. The code block I shared is back-end code and requires a premium Code Manager license (see code block description). Nothing happens when you execute that code from a php shortcode.

    There are two ways to solve this issue:
    (1) Get a premium license
    (2) Add the ajax action manually

    Here is the WordPress documentation if you want to add the ajax action manually:
    https://developer.www.ads-software.com/plugins/javascript/enqueuing/

    Let me know if this help… ??

    God luck,
    Peter

    Thread Starter wolfshui

    (@wolfshui)

    I purchased the premium version of code manager, I will try to Ajax action.

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Just make sure the code block is back-end code! ??

    Does this help?
    Peter

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Mixing Programing Languages’ is closed to new replies.