/    Sign up×
Community /Pin to ProfileBookmark

Multiple selection

Hi All,

I want to ask if there’s someone who can help me with check box. I want to select more than one checkbox let say 2, 3 or 4.But I’ am stucked at only one checkbox.The following are my codes to display tables from mysql and display it.
Thanks.

[code=php]<?php
$bsc = $_POST[1];
$kbsc = $_POST[2];
$rbsc = $_POST[3];
$hbsc = $_POST[4];
?>

<?php
$table=”Site”;
$conn = mysql_connect(“localhost”, “root”, “juju”) or die(mysql_error());
mysql_select_db(“tigo”) or die(mysql_error());

// selects db listings for KIBSC01
if ($bsc) {
$query = “SELECT Site_ID, Site_Name, Latitude, Longitude, BTS_Type, Band, Technical_Region, Commercial_Territory FROM Site WHERE BSC_ID = ‘$bsc'”;
$result = mysql_query($query) or die(mysql_error());

// selects db listings for KIBSC02
} elseif($kbsc) {
$query = “SELECT Site_ID, Site_Name, Latitude, Longitude, BTS_Type, Band, Technical_Region, Commercial_Territory FROM Site WHERE BSC_ID = ‘$kbsc'”;
$result = mysql_query($query) or die(mysql_error());

// selects db listings for KRBSC01
} elseif($rbsc) {
$query = “SELECT Site_ID, Site_Name, Latitude, Longitude, BTS_Type, Band, Technical_Region, Commercial_Territory FROM Site WHERE BSC_ID = ‘$rbsc'”;
$result = mysql_query($query) or die(mysql_error());

// selects db listings HYBSC01
} elseif($hbsc) {
$query = “SELECT Site_ID, Site_Name, Latitude, Longitude, BTS_Type, Band, Technical_Region, Commercial_Territory FROM Site WHERE BSC_ID = ‘$hbsc'”;
$result = mysql_query($query) or die(mysql_error());
// Select db listing KIBSC01 and KIBSC02

} elseif($bsc || $kbsc) {
$query = “SELECT Site_ID, Site_Name, Latitude, Longitude, BTS_Type, Band, Technical_Region, Commercial_Territory FROM Site WHERE BSC_ID = ‘$bsc’ OR BSC_ID=’$kbsc'”;
$result = mysql_query($query) or die(mysql_error());
// Select db listing KIBSC01 and KIBSC02

} else {
$query = “SELECT Site_ID, Site_Name, Latitude, Longitude, BTS_Type, Band, Technical_Region, Commercial_Territory FROM Site WHERE BSC_ID= ””;
$result = mysql_query($query) or die(mysql_error());
}

if (!$result) {
die(“Query to show fields from table failed”);
}

$fields_num = mysql_num_fields($result);

//Set value to POST
if(isset($_POST[‘1’]) ){
echo “<table border=”1″>n”;
while ($row = mysql_fetch_assoc($result)) {
echo “<tr>n”;
foreach ($row as $bsc) {
echo “<td>n”;
echo $bsc;
echo “</td>n”;
}
echo “</tr>n”;
}
echo “</table>n”;
}
if(isset($_POST[‘2’])){
echo “<table border=”1″>n”;
while ($row = mysql_fetch_assoc($result)) {
echo “<tr>n”;
foreach ($row as $kbsc) {
echo “<td>n”;
echo $kbsc;
echo “</td>n”;
}
echo “</tr>n”;
}
echo “</table>n”;
}
if (isset($_POST[‘3’])) {
echo “<table border=”1″>n”;
while ($row = mysql_fetch_assoc($result)) {
echo “<tr>n”;
foreach ($row as $rbsc) {
echo “<td>n”;
echo $rbsc;
echo “</td>n”;
}
echo”</tr>n”;
}
echo “</table>n”;
}
if (isset ($_POST[‘4’])) {
echo “<table border=”1″>n”;
while ($row = mysql_fetch_assoc($result)) {
echo “<tr>n”;
foreach ($row as $hbsc) {
echo “<td>n”;
echo $hbsc;
echo “</td>n”;
}
echo “</tr>”;
}
echo “</table>n”;
}
?>[/code]

The above is checkbx.php which is in the following code.
And the code which contains checkboxes is the following:

[code=php]<form method=”POST” action=”checkbx.php” >
<input name=”1[]” type=”checkbox” id=”1″ value=”1″>KIBSC01<br />

<input name=”2[]” type=”checkbox” id=”2″ value=”2″>KIBSC02<br />

<input name=”3[]” type=”checkbox” id=”3″ value=”3″>KRBSC01<br />

<input name=”4[]” type=”checkbox” id=”4″ value=”4″>HYBSC01<br />

<input type=’submit’ value=’Submit’>

</form>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @ubugeni spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...