Im struggeling since 10 hours

Hello there,

so basically I’m familiar with scripting and most time I’m able to fix my things, even it it takes some hours, but now I’m out of brain.

Let’s go:

What I’m trying to do is, recreating a page with categories, (copied from source and adjusted the way to work… at least for 85%).

Whenever I’m trying to adjust a special-snippet of code, either it works to show in the webpage but without main functionallity (I’m able to click sections and see what’s in there, but can’t use the futures of the sections) or it throws out an 500 Internal Server Error with PHP Parse error: syntax error, unexpected end of file (Endline), which cannot be true, since I’ve checked it multiple times for missing ends…

Let’s show the code: (without Categories, which works like a charm:)

$queryj = mysqli_query($connect, "SELECT * FROM `crimes`");
while ($rowj = mysqli_fetch_assoc($queryj)) {
    $job_id   = $rowj['id'];
    $querypac = mysqli_query($connect, "SELECT * FROM `player_actions` WHERE player_id='$player_id' LIMIT 1");
    $rowpac   = mysqli_fetch_assoc($querypac);
    $countpac = mysqli_num_rows($querypac);
            <div class="col-md-6">

Alright, now let’s see the code which I’ve changed and it does not work.
I tried multiple adjustions, movments, it however gives me a 500 Internal Server Error, as soon as we came to Var: $firsta

$first   = true;
$queryic = mysqli_query($connect, "SELECT * FROM `crime_categories`");
while ($rowic = mysqli_fetch_assoc($queryic)) {
                    <li <?php
    if ($first) {
        echo 'class="active"';
        $first = false;
?></l><a data-toggle="tab" href="#<?php
    echo $rowic['id'];
?>"><i class="fa <?php
    echo $rowic['fa_icon'];
?>"></i> <?php
    echo $rowic['category'];

                <div class="tab-content">
$firsta   = true;
$queryicc = mysqli_query($connect, "SELECT * FROM `crime_categories`");
while ($rowicc = mysqli_fetch_assoc($queryicc)) {
    $category_id = $rowicc['id'];
                        <div id="<?php
    echo $category_id;
?>" class="tab-pane fade in <?php
    if ($firsta) {
        echo 'active';
        $firsta = false;
                    <br />
                    <div class="row">
    $queryi = mysqli_query($connect, "SELECT * FROM `crimes` WHERE category_id = '$category_id'");
    while ($rowi = mysqli_fetch_assoc($queryi)) {

        $item_id  = $rowi['id'];
        $querypic = mysqli_query($connect, "SELECT * FROM `player_actions` WHERE player_id='$player_id' LIMIT 1");
        $rowpic   = mysqli_fetch_assoc($querypic);
        $countpic = mysqli_num_rows($querypic);

However, thank you for your time to read my problems, and hopefully respond.

EDIT: Oh no, I guess I was simple too long at that script. NVM. I found it. But if someone would want to quickly help me transfer that line to make it work without 500 Error, I would be very happy.

Error lies:

  if ($countpac > 0 && $rowpac['type'] == $rowj['crime_type'] && time() >= $rowpac['finishtime']) {
        echo '<a href="?finish-work=' . $rowj['id'] . '" class="btn btn-success btn-md btn-block"><i class="far fa-money-bill-alt"></i>&nbsp; ' . lang_key("get-salary") . '</a>';
    } else if ($countpac > 0 && $rowpac['type'] == $rowj['crime_type'] && time() < $rowpac['finishtime']) {
        $timeleft = secondsToWords($rowpac['finishtime'] - time());
        echo '<div class="row"><div class="col-md-6"><button class="btn btn-warning btn-md btn-block disabled"><em class="fas fa-fw fa-clock"></em> ' . $timeleft . '</button></div><div class="col-md-6"><a href="?leave-work=' . $rowj['id'] . '" class="btn btn-info btn-md btn-block"><i class="fa fa-sign-out-alt"></i>&nbsp; ' . lang_key("leave-work") . '</a></div></div>';
    } else if ($rowu['energy'] < $rowj['energy_cost'] || $rowu['health'] < $rowj['health_loss'] || $countpac > 0) {
        echo '<button class="btn btn-danger btn-md btn-block" disabled><em class="fa fa-fw fa-cogs"></em> ' . lang_key("start-work") . '</button>';
    } else {
        echo '<a href="?job-id=' . $rowj['id'] . '" class="btn btn-info btn-md btn-block"><i class="fa fa-cogs"></i>&nbsp; ' . lang_key("start-work") . '</a>';


Look into the error.log of your webserver.

Thanks for your reply. I figured out what causes the issue, however it’s the complete endling line, which not works as I wish it to work. I will try to rewrite the last part as well.

the error.log only tells me, that he faced an unexpected end of a file, I tought about an exclamination mark e.g. but well.

Thanks anyhow

The snippets of posted code, provided that all the while loops have closing }, do not contain any syntax errors. The problem is where/how these pieces of code are being used on the page.

Some recommendations -

  1. Do not run queries inside of loops. To retrieve related data, use a single JOIN query to get the data you want all at once.
  2. Do not put the database specific code inside the html document. You should put the database specific code before the start of the html document and fetch the data into appropriately named php variables. This makes writing and testing the code/query(ies) easier and will simplify the code in the html document, which will probably eliminate your existing problem.
  3. Use a simple template system to produce the html markup.
  4. Don’t create variables without a good reason.
  5. Don’t put external/unknown data directly into sql queries. User prepared queries.
  6. Don’t Repeat Yourself (DRY.) Don’t repeat logic, queries, markup, …
Sponsor our Newsletter | Privacy Policy | Terms of Service