I have this form
<form class="account-form" method="post">
<input type="radio" name="all" />All<br />
<input type="radio" name="part" />Part<br />
<label>How many channels to export?</label><br />
<input type="number" name="part" value="" /><br />
<label>Select user</label><br />
<input type="test" name="user" value="" /><br />
<label>Execlude user</label><br />
<input type="test" name="exuser" value="" /><br />
<label>Select numbers region</label><br />
<input type="checkbox" name="uk" value="uk" />Export UK<br />
<input type="checkbox" name="us" value="us" />Export US <br />
<button type="submit" name="submit" value="submit" />Submit <br />
</form>
and I want to export some data form my db according to the choices in the form so far I'm doing it like this
if (isset($_POST)){
if (isset($_POST[all])){
$file = '../files/'.$notsoldcount." All.txt";
$fp=fopen($file,"w");
while($row = mysql_fetch_array($notsold, MYSQL_ASSOC))
{
$phone = $row['phone'] ;
$pass = $row['password'] ;
$id = $row['identity'] ;
$data = $phone.",".$pass.",".$id.","."\r\n";
fwrite($fp,$data);
mysql_query("UPDATE `datask` SET `sold`= 1 WHERE phone = '$phone'");
}
fclose($fp);
echo '
<div class="alert alert-warning alert-dismissible" role="alert">
<strong>Okey!</strong> Your file is ready for <a download href="'.$file.'">Download</a>
</div>
';
}
else {
if (isset($_POST[part]) && ($_POST[uk])){
$some = $_POST[some];
// Same here
}
else if (isset($_POST[some]) && ($_POST[us])){
// same here
}
else if (isset($_POST[some] && ($_POST[user])){
//same
}
and so on for all choices
}
}
I need to export data according the choices but there are a lot of odds like
- all data
- all data excluding 1 user
- all data for 1 user
- part of the data :
- part for all users
- part for all users excluding 1 user
- part for all users for us numbers
- part for all users for uk numbers
- part for 1 user for us numbers only
- part for 1 user for uk numbers only
using if, else if statements will result in a very long code, is there any way to shorten it?
Aucun commentaire:
Enregistrer un commentaire