Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Need advice how to view PHP

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #156769
    moer
    Participant

    Looking for some advice how to view like this not like this

    For reference:-
    //this is how i create the table
    mysql_query(“CREATE TABLE example(
    roomtype VARCHAR(30),
    Jan1 INT,
    Jan2 INT,
    Jan3 INT)”)
    or die(mysql_error());

    // this is how i insert the data into the table
    mysql_query(“INSERT INTO example
    (roomtype, Jan1, Jan2, Jan3) VALUES(‘Deluxe’, ‘255’, ‘255’, ‘255’ ) “)
    or die(mysql_error());

    mysql_query(“INSERT INTO example
    (roomtype, Jan1, Jan2, Jan3) VALUES(‘Suite’, ‘330’, ‘330’, ‘330’ ) “)
    or die(mysql_error());

    // This is where my problem how to view the data as per link
    $result = mysql_query(“SELECT * FROM example”)
    or die(mysql_error());

    $row = mysql_fetch_array( $result );

    echo “roomtype: “.$row[‘roomtype’];
    echo ” Jan1: “.$row[‘Jan1’];
    echo ” Jan2: “.$row[‘Jan2’];
    echo ” Jan3: “.$row[‘Jan3’];

    .

    #156771
    danramosd
    Participant

    You want to use an HTML table. Where you have the 4 lines that echo out the values you will want to change that to this:

    <table>
    <tr>
    <th></th>
    <th colspan='3'>January</th>
    </tr>
    <tr>
    <td><?php echo “roomtype: “.$row['roomtype'];  ?> </td>
    <td><?php echo ” Jan1: “.$row['Jan1'];  ?> </td>
    <td><?php echo ” Jan2: “.$row['Jan2'];  ?> </td>
    <td><?php echo ” Jan3: “.$row['Jan3'];  ?> </td>
    </table>
    
    #156779
    moer
    Participant

    Tried it. The html table works but the php only pulls the variable only with no data. So i can see roomtype, Jan1, Jan2 & Jan3 nicely in place. However the data Deluxe, 255, 255, 255 are not generated.

    Any idea?

    #156792
    danramosd
    Participant
    <table>
    <tr>
    <th></th>
    <th colspan='3'>January</th>
    </tr>
    <?php while( $row = mysql_fetch_array( $result ) ){ ?>
    <tr>
    <td><?php echo “roomtype: “.$row['roomtype'];  ?> </td>
    <td><?php echo ” Jan1: “.$row['Jan1'];  ?> </td>
    <td><?php echo ” Jan2: “.$row['Jan2'];  ?> </td>
    <td><?php echo ” Jan3: “.$row['Jan3'];  ?> </td>
    </tr>
    <?php } ?>
    </table>
    

    Try that. If it doesn’t work you might not have any data in your array. To find out if that’s true try running

    <?php print_r( $row ) ;?>
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.