0

Im making search button and i want when user is searched to give all tickets received by that user i have this code but its just showing the last record of that db table and if i try to search other users gives me No ticket received from that user. but this is false, i have tickets from that user.

functions.php

function show_tickets($sender_tickets="") {
        global $conn;
        $user = getUserData('users', 'UserUsername');
        $sql = "SELECT senderName, receiverName, `Date`, ticketID, match1, match2, match3, match4, match5, match6, match7, match8, match9, match10, match11, match12, match13, match14, match15, match16, tip1, tip2, tip3, tip4, tip5, tip6, tip7, tip8, tip9, tip10, tip11, tip12, tip13, tip14, tip15, tip16, Bet, Gain, Odd, seen FROM ticket WHERE receiverName='".$user."'";
        $result = $conn->query($sql);

        if(!$result) {
            trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
        } else {
            if($result->num_rows == 0) {
                echo "You have not received any ticket";
            } else if($result->num_rows >= 1) {
                while($row = $result->fetch_assoc()) {
                    $ticket_id = $row['ticketID'];

                    $sender_tickets = array($ticket_id);

                }
                foreach($sender_tickets as $key => $value) {
                    echo "&nbsp" . $value . "&nbsp";
                    return $sender_tickets;
                }
            }
        }
    }

messages.php Search Button

if(isset($_POST['searchBtn'])){
            $search_btn = $_POST['searchBtn'];
            $user = getUserData('users', 'UserUsername');

            $sql = "SELECT senderName FROM ticket WHERE receiverName='{$user}'";
            $result = $conn->query($sql);

            if(!$result) {
                trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
            } else {
                if($result->num_rows == 0) {
                    echo "You have not received any ticket";
                } else if($result->num_rows >= 1) {
                    while($row = $result->fetch_assoc()) {
                        $senderName = $row['senderName'];

                    }

                    if(strtolower($search_btn) == strtolower($senderName)) {
                        echo "Sender found, " . $senderName;
                        show_tickets($senderName);
                    } else {
                        ?>
                        <p>No ticket received from that user.</p>
                        <?php
                    }

                }
            }
        }

Edited by Stefan_1

2
Contributors
3
Replies
19
Views
1 Year
Discussion Span
Last Post by Stefan_1
0

In the first snippet, change:

$sender_tickets = array($ticket_id);

to:

$sender_tickets[] = $ticket_id;

and swap lines 21 and 22.

0

Fatal error: [] operator not supported for strings in C:\xampp\htdocs\bootstrap\functions.php on line 219 ($sender_tickets[] = $ticket_id;)

BTW again doesnt find the other users

Edited by Stefan_1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.