Jump to content

Recommended Posts

Hi Guys.

Maybe you can help me with this problem I have:

I have two tables, Packages and Tours, I need to associate tours with several packages.  I found the solution to insert the data into the DB using implode (Worked great).  The info on the DB look like this: (1,3,5)

On the table Tours I have Checkboxes where you can choose your Packages as follows:

<?php do {?>
<table width="530" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="18"><input type="checkbox" name="id_packages[]" value="<?php echo $row_package['id_packages']?>"/></td>
<td><?php echo $row_package['name']?></td>
</tr>
</table>
<?php
} while ($row_package = mysql_fetch_assoc($package));
?>

Here's the BIG question:  I want to retrieve the information from the database and have the checkboxes "selected" with the info on the database.  I tried explode but no luck.  Thanks for the help.
Link to comment
https://forums.phpfreaks.com/topic/33665-retrieve-checkboxes-selected/
Share on other sites

Lol, I was just givin you crap.  I'm not sure what exactly you are trying to do though, but your code you have far should be like this i think:

[code]
<?php


while ($row_package = mysql_fetch_assoc($package)) {
<table width="530" border="0" cellspacing="0" cellpadding="5">

foreach($row_package as $key => $row) {

echo"
<tr>
<td width=\"18\"><input type=\"checkbox\" name=\"".$key."\" value=\"" .$row['id_packages']."\"></td>
<td>$row_package['name']</td>
</tr>";

}
</tr>
</table>
}
?>[/code]
its ok by me julian! I very much prefer to break out of php when formatting html - only keep html in echo statements when there is very small amounts of html to do.

OK

Its a little confusing what you wish to achive BUT just to be clear this is what I think you are trying to do.

You show a table of tours and in that table you show which packages have that tour. The you want the users to select which packages they want.

[code]
<?php
$tour = "SELECT * FROM `tours` WHERE `tour_id` = " . $_GET['tour_id'];
$tour = mysql_query($tour);
$tour = mysql_fetch_assoc($tour);

$pack = "SELECT * FROM `packages` WHERE `package_id` IN (. $tour['packages'] .)";
$pack = mysql_query($pack);
?>
<table width="530" border="0" cellspacing="0" cellpadding="5">
<tr>
<td class="tourtitle"><?php echo $tour['title']; ?></td>
</tr>
<?php
while ($row_package = mysdql_fetch_assoc($pack))
{
?>
<tr>
<td>
<label>
<input type="checkbox" name="id_packages[]" value="<?php echo $row_package['id_packages']?>" />
<?php echo $row_package['name']?>
</label>
</td>
</tr>
<?php
}
?>
</table>
[/code]

I think that should do the trick.

Thanks for the big help ToonMariner, I'm getting this error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in...

On this line:

$pack = "SELECT * FROM `packages` WHERE `package_id` IN (. $tour['packages'] .)";

Maybe something is missing.  Thanks again.
Thanks Huggie!

I echo'ed the $tour['id_packages'] got 1,3

I think this is working good.  But I think that's is not what I'm looking for.

Table Packages something like this:

id_packages  |    name
      1          |  Beach Vacations
      2          |  Mountain
      3          |  Coasts

Table Tours something like this:

id_tour  |  id_packages  |  tour
      1    |          1,3        |  Surfing

I inserted the array in the Table Tours, so good so far.

I want to retrieve this array as checked boxes depends on the choice I made earlier.

Thanks guys, you're the best....
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.