skip to Main Content

I want to generate a list in pdf of the passengers on a bus ride.

My problem is, that in every second cell on the right side, there is the same person from the first cell in every row.

Preview of the table

And i want to order them with "ut_utasok_ules_pozicio" column. This means the seat number on the bus.

My code is:

`$html .= ”;

    while($aa = mysqli_fetch_assoc($adat))
    {
        $html .= '<tr>
                    <td>'.$aa['ut_utasok_ules_pozicio'] . '. ' . $aa['utas_nev'] . '</td>
                    <td>'.$aa['ut_utasok_ules_pozicio'] . '. ' . $aa['utas_nev'] . '</td>
                 </tr>';
    }
    
    $html .= '</table>';`

I tried modify my sql query, but i think the problem isnt there.

2

Answers


  1. I used Google Translate to understand your fields; it suggests that "utas név" is Hungarian for "passenger name."

    In your code, you have two identical cells with identical data:

    $html .= '<tr>
                    <td>'.$aa['ut_utasok_ules_pozicio'] . '. ' . $aa['utas_nev'] . '</td>
                    <td>'.$aa['ut_utasok_ules_pozicio'] . '. ' . $aa['utas_nev'] . '</td>
                 </tr>';
    

    This is why you see the same content in both cells.

    I think you might want to display the seat number in the first cell and the passenger name in the second cell, like this:

    $html .= '<tr>
                        <td>'. $aa['ut_utasok_ules_pozicio'] . '</td>
                        <td>' . $aa['utas_nev'] . '</td>
                     </tr>';
    

    Regarding your comment:

    i want to order them with "ut_utasok_ules_pozicio" column

    it seems your records are already sorted, as the numbers from 1 to 4 appear in the correct order.

    Please consider reviewing the basics of HTML. You can start here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td

    Login or Signup to reply.
  2. I’m sure you want to display the number on the left and the name on the right. I see that PHP can retrieve data from the database correctly, it just needs adjustments in the PHP code.

    <table>
        <?php while($d = mysqli_fetch_assoc($data)) { ?>
            <tr>
                <td><?= $d['ut_utasok_ules_pozicio']; ?></td>
                <td><?= $d['utas_nev']; ?></td>
            </tr>
        <?php } ?>
    </table>
    

    As you can see from the code above, I have organized the code you created to make it easier to read, and in the future, if there is a need for corrections, it will be easier to fix.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search