Jump to content

[SOLVED] Whats the best way?


aim25

Recommended Posts

Okay, i'm making a sign up page. When you are signing up you get the option of choosing which newsletters you would like to receive. I put the information in an array called news:

 

<?php

//array broken down

$news[0] = $_POST['weekly'];
$news[1] = $_POST['news1'];
$news[2] = $_POST['news2'];
$news[3] = $_POST['news3'];
$news[4] = $_POST['news4'];
$news[5] = $_POST['news5'];
$news[6] = $_POST['news6'];
$news[7] = $_POST['news7'];
$news[8] = $_POST['news8'];
$news[9] = $_POST['news9'];

?>

 

So now i'm going to store this information into my db:

 

<?php
//this is the main part

if(!empty($news[0])) {
mysql_query("INSERT INTO members(news1) VALUES ('1');");
}

// and then ill repeat the code above for each news letter, editing the values ofcourse
?>

 

But the problem is that this may get lengthy, so i'm looking for a better way to do this.

 

Note: on the html page the the input fields for the newsletters are checkboxes

Link to comment
https://forums.phpfreaks.com/topic/57321-solved-whats-the-best-way/
Share on other sites

Write a for loop that loops through each element of your array and tests for empty. If it's not empty, grab what's inside a run a function on it.

 

setUserNewsLetter($arrayElement) {

$qry="UPDATE news SET newslettertosend='$arrayElement'";

}

 

Something like that.

 

IDK how your db is structured or if they can pick more than one newsletter or anything so there could be mroe to it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.