jamesreno20 Posted November 22, 2014 Share Posted November 22, 2014 i have checkboxes on the database page and if checked they send to the shopping basket i have the items selected to display but like this Array ( [0] => Imagine DragonsImagine DragonsRockI Bet My LifeKIDinaKORNER1.25Brand new single from the incredible Imagine Dragons ) i want it to be like this Imagine Dragons Imagine Dragons Rock I Bet My Life KIDinaKORNER 1.25 Brand new single from the incredible Imagine Dragons here is my code ____________________________________________________________________ database.php <form name="test" method="post" action="shoppingbasket.php" > $res = pg_query ($conn, "SELECT ref,artist,composer,genre,title,album,label,price,description FROM music"); echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th> <th>Price</th><th>Description</th></tr>"; while ($row = pg_fetch_row($res)) { echo "<tr>"; echo '<td><input type="checkbox" name="check_list[]" value="'. $row[1]. $row[2]. $row[3].$row[4].$row[5].$row[6].$row[7].$row[8].$row[9].'"></td>'; for ($column = 1; $column < pg_num_fields($res); $column++) { echo "<td>" . $row[$column] . "</td>"; } echo "</tr>"; } echo "</table>\n"; ?> <input type="submit" value="Submit" > __________________________________________________________________________- shppingbasket.php <?php print "<pre>"; print_r($_POST['check_list']); print "</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/292649-how-to-display-print_r-array-in-seperate-columns/ Share on other sites More sharing options...
ginerjm Posted November 22, 2014 Share Posted November 22, 2014 So? Use some formatting in your output of the data. You began a table and defined all the headings but then you didn't output any columns to correspond to those headings. Do you have an html resource that you use? Then use it to learn how an html table is built. Quote Link to comment https://forums.phpfreaks.com/topic/292649-how-to-display-print_r-array-in-seperate-columns/#findComment-1497348 Share on other sites More sharing options...
NotionCommotion Posted November 23, 2014 Share Posted November 23, 2014 Assuming "ref" in your database corresponds to the checkbox, this line... echo '<td><input type="checkbox" name="check_list[]" value="'. $row[1]. $row[2]. $row[3].$row[4].$row[5].$row[6].$row[7].$row[8].$row[9].'"></td>'; should be... echo '<td><input type="checkbox" name="check_list[]" value="'. $row[0].'"></td>'; That being said, why have the mini-loop to display columns? Typically, you just want the row loop and echo each column independently (at least that is how I do it I also usually use associated or object outputs from the DB so need to use the name). Quote Link to comment https://forums.phpfreaks.com/topic/292649-how-to-display-print_r-array-in-seperate-columns/#findComment-1497350 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.