Jump to content

[SOLVED] Extra Checkbox?


phpretard

Recommended Posts

I have a feild called counties in my DB with the following values:

 

 

HARDEE, HILLSBOROUGH, JACKSON, JEFFERSON, LAKE, LEE, LEON, LIBERTY, MADISON

 

 

I just want them to show up with a checkbox for each one.  I keep getting 1 EXTRA CHECKBOX

 

 

Any help today?

 

<?

$result = mysql_query("SELECT * FROM members WHERE State='$LicState' ORDER by Counties");

while($row = mysql_fetch_array($result))
{

$Counties=$row['Counties'];

$County2 = explode(',', $Counties);

foreach ($County2 as $County1) {

$size = count($County1);

for ($i=0; $i<$size; ++$i){

echo "<div style='width:24%; float:left; font-size:13px;'><input type=checkbox name=Counties[] Value='$County1'>$County1</div>"; 

} 

}

}

?>

Link to comment
Share on other sites

You have too many loops. Try:

<?php
$result = mysql_query("SELECT * FROM members WHERE State='$LicState' ORDER by Counties");
while($row = mysql_fetch_array($result)) {
       $Counties=explode(',',$row['Counties']);
       foreach ($Counties as $County1)
           echo "<div style='width:24%; float:left; font-size:13px;'><input type='checkbox' name='Counties[]' Value='$County1'>$County1</div>"; 
}
?>

 

Ken

Link to comment
Share on other sites

That is truly fantastic !! you shortened the code...but

 

the print_r

 

Shows 2

 

Array ( [0] => ) one with NO VALUE (the empty checkbox of course)

 

and then the rest of the array with all of the needed values.

 

How do I get rid of Array ( [0] => )?

Link to comment
Share on other sites

TEXT FEILD IN DB EXACTLY: "HARDEE, HILLSBOROUGH, JACKSON, JEFFERSON, LAKE, LEE, LEON, LIBERTY, MADISON"

 

Where is the empty array comming from or better yet how do I get rid of it?

 

I have read into ---$size = intval(count($County1) - 1);--- but am not sure where or how to implement such a beast.

 

print_r yeilds:

 

Array ( [0] => )

 

Array ( [0] => HARDEE [1] => HILLSBOROUGH [2] => JACKSON [3] => JEFFERSON [4] => LAKE [5] => LEE [6] => LEON [7] => LIBERTY [8] => MADISON )

 

//END

 

Code Again:

 

$result = mysql_query("SELECT * FROM members WHERE State='$LicState' ORDER by Counties");

while($row = mysql_fetch_array($result)) 
{

$Counties=explode(',',$row['Counties']);

foreach ($Counties as $County1)

echo "<div style='width:24%; float:left; font-size:13px;'><input type='checkbox' name='Counties[]' Value='$County1'>$County1</div>";

}

 

Link to comment
Share on other sites

TEXT FEILD IN DB EXACTLY: "HARDEE, HILLSBOROUGH, JACKSON, JEFFERSON, LAKE, LEE, LEON, LIBERTY, MADISON"

 

Where is the empty array comming from or better yet how do I get rid of it?

 

I have read into ---$size = intval(count($County1) - 1);--- but am not sure where or how to implement such a beast.

 

print_r yeilds:

 

Array ( [0] => )

 

Array ( [0] => HARDEE [1] => HILLSBOROUGH [2] => JACKSON [3] => JEFFERSON [4] => LAKE [5] => LEE [6] => LEON [7] => LIBERTY [8] => MADISON )

 

//END

 

Code Again:

 

$result = mysql_query("SELECT * FROM members WHERE State='$LicState' ORDER by Counties");

while($row = mysql_fetch_array($result)) 
{

$Counties=explode(',',$row['Counties']);

foreach ($Counties as $County1)

echo "<div style='width:24%; float:left; font-size:13px;'><input type='checkbox' name='Counties[]' Value='$County1'>$County1</div>";

}

Post the code you're using including the print_r() you're using.

 

----------------

Now playing: Dance Gavin Dance - It's Safe to Say You Dig the Backseat

via FoxyTunes

Link to comment
Share on other sites

PHP CODE:

 

$result = mysql_query("SELECT * FROM members WHERE State='$LicState' ORDER by Counties");

while($row = mysql_fetch_array($result)) 
{

$Counties=explode(', ' , $row['Counties']);

foreach ($Counties as $County1)

echo "<div style='width:24%; float:left; font-size:13px;'><input type='checkbox' name='Counties[]' Value='$County1'>$County1</div>";

print_r($Counties);

}

 

HTML OUTPUT (MINUS THE STYLE INFO):

 

<div><input type='checkbox' name='Counties[]' Value=''></div>   <<<<<<<<<<<<<< HE WONT GO AWAY
<div><input type='checkbox' name='Counties[]' Value='HARDEE'>HARDEE</div>
<div><input type='checkbox' name='Counties[]' Value='HILLSBOROUGH'>HILLSBOROUGH</div>
<div><input type='checkbox' name='Counties[]' Value='JACKSON'>JACKSON</div>
<div><input type='checkbox' name='Counties[]' Value='JEFFERSON'>JEFFERSON</div>
<div><input type='checkbox' name='Counties[]' Value='LAKE'>LAKE</div>
<div><input type='checkbox' name='Counties[]' Value='LEE'>LEE</div>
<div><input type='checkbox' name='Counties[]' Value='LEON'>LEON</div>
<div><input type='checkbox' name='Counties[]' Value='LIBERTY'>LIBERTY</div>
<div><input type='checkbox' name='Counties[]' Value='MADISON'>MADISON</div>

 

 

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.