Jump to content

php arrays


randyw

Recommended Posts

Im new to php i have written some code to get info from chexboxes.

 

<input type="checkbox" name="shows_Selected[]" value="January 24, 2010  Granite Links Golf Club, Quincy, MA" tabindex="10">

      January 24, 2010 - Granite Links Golf Club, Quincy, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="January 31, 2010  Sheraton Ferncroft, Danvers, MA" tabindex="15">

      January 31, 2010 - Sheraton Ferncroft, Danvers, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="February 7, 2010  Crowne Plaza, Natick, MA" tabindex="20">

      February 7, 2010 - Crowne Plaza, Natick, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="February 14, 2010  Indian Pond Country Club, Kingston, MA" tabindex="25">

      February 14, 2010 - Indian Pond Country Club, Kingston, MA<br>

 

<input type="checkbox" name="shows_Selected[]" value="February 21, 2010  Burlington Marriott, MA" tabindex="30">

      February 21, 2010 - Burlington Marriott, MA</font> <font color="#666666"><br>

 

 

 

$media_array = $_POST['shows_Selected'];

foreach ($media_array as $one_media) {

$source .= $one_media."<br>";

}

$shows_Selected = substr($source, 0, -2);

 

 

// update data in mysql database

$sql = "INSERT INTO newportweddingExpoForm

(shows_Selected, additional_Info, first_name, last_name, Role, email_address, home_phone, work_phone, city, state, zip, mailling_address, apt_number, wedding_month, wedding_day, wedding_year, Wedding_Tentative, wedding_Region, wedding_city, wedding_state, budget, find_aboutUs)VALUES('$shows_Selected', '$additional_Info', '$first_name', '$last_name', '$role', '$email_address', '$home_phone', '$work_phone', '$city', '$state', '$zip', '$mailling_address', '$apt_number', '$wedding_month', '$wedding_day', '$wedding_year', '$Wedding_Tentative', '$wedding_Region', '$wedding_city', '$wedding_state', '$budget', '$find_aboutUs')";

$result = @mysql_query($sql);

 

 

<? echo $row['additional_Info'];?> this is how i get the data out

 

<input type="checkbox" name="additional_Info[]" value="Yes, sign me up to receive helpful newsletters via email" checked tabindex="145"></td>

<input type="checkbox" name="additional_Info[]" value="Yes, I'd like to receive info on wedding related specials via "snail" mail." checked tabindex="150">

 

shows_Selected works now i need to do the same thing for additional_info with 5 check boxes

 

and so on for futher_Info with 45 check boxes

Link to comment
Share on other sites

What is your question? you say you were able to do it once successfully, so you "could" do the same for the rest, correct?

 

I will however make a few suggestions. Since you have a many-to-one relationship I would suggest putting the 'shows_Selected' values into a secondary table with a reference back to the parent record - rather than concatenating all the values into a single value in the database. The current method you are using loses some of the integrity of the data.

 

However, that aside, your current process of concatenating the values is inefficient as well. You could replace this

$media_array = $_POST['shows_Selected'];
foreach ($media_array as $one_media) {
$source .= $one_media."<br>";
}
$shows_Selected = substr($source, 0, -2);

with just this

$shows_Selected = implode('<br>', $_POST['shows_Selected']);

 

I also notice you are storing three different values for the wedding day/month/year. You can just store a single timestamp value instead of all three. then parse that value for day/month/year as needed.

Link to comment
Share on other sites

What is your question? you say you were able to do it once successfully, so you "could" do the same for the rest, correct?

 

I will however make a few suggestions. Since you have a many-to-one relationship I would suggest putting the 'shows_Selected' values into a secondary table with a reference back to the parent record - rather than concatenating all the values into a single value in the database. The current method you are using loses some of the integrity of the data.

 

However, that aside, your current process of concatenating the values is inefficient as well. You could replace this

$media_array = $_POST['shows_Selected'];
foreach ($media_array as $one_media) {
$source .= $one_media."<br>";
}
$shows_Selected = substr($source, 0, -2);

with just this

$shows_Selected = implode('<br>', $_POST['shows_Selected']);

 

I also notice you are storing three different values for the wedding day/month/year. You can just store a single timestamp value instead of all three. then parse that value for day/month/year as needed.

 


 

idont know how to do same for the rest

 

$media_array2 = $_POST['additional_Info'];

foreach ($media_array2 as $one_media) {

$source2 .= $one_media."<br>";

}

$shows_Selected = substr($source2, 0, -2);

 

does not work

Link to comment
Share on other sites

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.