0

I'm creating events CMS and i'm some difficulty with getting the data from the table in the mysql to display if a format that i would like. Also, for some reason the data is is replicating the event number across all fields.

<?php
    require("includes/con.php");
?>

<?php
    $queryVENUE = "SELECT * FROM venue ORDER BY event_date"; //pulls all data from the venue table.
    $resultVENUE = $mysqli->query($queryVENUE);

    $eventsNameArray = array();
    while ($rowEvents = $resultVENUE->fetch_assoc()) {
        $eventsNameArray[] = $rowEvents['event_id'] . " " . $rowEvents['event_date'] . " " . $rowEvents['event_name'] . " " . $rowEvents['event_location'] . " " . $rowEvents['event_details'] . " " . "&pound" . $rowEvents['event_ticket_cost']   ;
    }

    foreach($eventsNameArray as $eventsOutput){
        echo "<p>{$eventsOutput}</p>";

        echo "<H3>Event Number: {$eventsOutput['event_id']}</H3>";
        echo "<p>Event Date: {$eventsOutput['event_date']}</p>";
        echo "<p>Event Name: {$eventsOutput['event_name']}</p>";
        echo "<p>Event Location: {$eventsOutput['event_location']}</p>";
        echo "<p>Event Details: {$eventsOutput['event_details']}</p>";
        echo "<p>Event Ticket Cost: {$eventsOutput['event_ticket_cost']}</p>";
    }

the output that I'm currently getting is this: 1 2013-11-21 Xscape Castleford Meet at the Hubs for 5pm. £5.00

Event Number: 1

Event Date: 1

Event Name: 1

Event Location: 1

Event Details: 1

Event Ticket Cost: £1

2 2013-11-24 Riding Rossendale Come ride at Rossendale in Manchester and get some practice in before the holiday! £5.00

Event Number: 2

Event Date: 2

Event Name: 2

Event Location: 2

Event Details: 2

Event Ticket Cost: 2

The aim to display the following: --row 1--

Event Number:

Event Date:

Event Location:

Event Details:

--row 2 --

Event Number:

Event Date:

Event Location:

Event Details:

Also i would like to put each section event number etc. into seperate Div's so i can style with css.

Thanks for any help in advance.

2
  • Are you saying that too much data is being displayed, and you don't want to show the name, or ticket cost? Commented Dec 27, 2013 at 19:45
  • Without understanding what the data is in your DB table, it is hard to answer thie question. As far as adding <div>'s goes, what have you tried? All you really need to do is just add more HTML as you like it, then just fill in the dynamic content into your HTML using PHP. So my suggestion is to build the HTML the way you want it first with hard-coded fake data, then you substitute the dynamic data once you have it the way you want it. Commented Dec 27, 2013 at 19:45

2 Answers 2

1

You are setting $eventsNameArray[] as a concenated string, where it looks like you need to do it as an array. Something like -

while ($rowEvents = $resultVENUE->fetch_assoc()) {
       $eventsNameArray[] = array(
              'event_id'=> $rowEvents['event_id'],
              'event_date'=> $rowEvents['event_date'], 
              'event_name'=> $rowEvents['event_name'],
              'event_location'=> $rowEvents['event_location'],
              'event_details'=> $rowEvents['event_details'],
              'event_ticket_cost'=> "&pound".$rowEvents['event_ticket_cost']
       );
}

or as @chas688 points out, more simply -

while ($rowEvents = $resultVENUE->fetch_assoc()) {
       $eventsNameArray[] = $rowEvents;
}
Sign up to request clarification or add additional context in comments.

1 Comment

The return is an associative array, so you don't need to re-associate it. You could simply do: $eventsNameArray[] = $rowEvents; and then foreach($rowEvents as $event){ echo $event['event_id'];, etc etc } in the view or your script quite simply. Adding &pound is prob. not a good idea to do until you echo out the array, anyway.
0

try to use data population like this, did you check your query on on database directly?

<?php
require("includes/con.php");
?>

    <?php
    $queryVENUE = "SELECT * FROM venue ORDER BY event_date"; //pulls all data from the venue table.
    $resultVENUE = $mysqli->query($queryVENUE);

    $eventsNameArray = array();
    while ($rowEvents = $resultVENUE->fetch_assoc()) {
    $eventsNameArray[] = $rowEvents['event_id'] . " " . $rowEvents['event_date'] . " " . $rowEvents['event_name'] . " " . $rowEvents['event_location'] . " " . $rowEvents['event_details'] . " " . "&pound" . $rowEvents['event_ticket_cost']   ;
    }
    ?>
    <table>
    <tr>
    <td>Event Number</td>
    <td>Event Date</td>
    <td>Event Name</td>
    <td>Event Location</td>
    <td>Event Details</td>
    <td>Event Ticket Cost</td>
    </tr>
    <?pho foreach($eventsNameArray as $eventsOutput){
    ?>
    <tr>


    <td><?php echo $eventsOutput['event_id']?></td>
    <td><?php echo $eventsOutput['event_date']?></td>
    <td><?php echo $eventsOutput['event_name']?></td>
    <td><?php echo $eventsOutput['event_location']?></td>
    <td><?php echo $eventsOutput['event_details']?></td>
    <td><?php echo $eventsOutput['event_ticket_cost']?></td>
    </tr>
    <?php }?>
    </table>

1 Comment

This won't work, since the $eventsNameArray is an array of a string, not associative values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.