Jump to content

Recommended Posts

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>";
?>

 

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.

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.