Jump to content

[SOLVED] value in array


Vivid Lust

Recommended Posts

Still isnt working!

 

Codes:

 

<?php
$b[1] = $row2['box1'];
$b[2] = $row2['box2'];
$b[3] = $row2['box3'];
$b[4] = $row2['box4'];
$b[5] = $row2['box5'];
$b[6] = $row2['box6'];
$b[7] = $row2['box7'];
$b[8] = $row2['box8'];
$b[9] = $row2['box9'];
$b[10] = $row2['box10'];
$b[11] = $row2['box11'];
$b[12] = $row2['box12'];
$b[13] = $row2['box13'];
$b[14] = $row2['box14'];
$b[15] = $row2['box15'];
?>

 

<input type="checkbox" name="a" value="http://www.cnn.com" <?php if(in_array("http://www.cnn.com",$b)){echo "checked";} ?>>CNN<br />
  <input type="checkbox" name="b" value="http://www.bbc.com" <?php if(in_array("http://www.bbc.com",$b)){echo "checked";}?>>BBC<br />
   <input type="checkbox" name="c" value="http://www.nbc.com" <?php if(in_array("http://www.nbc.com",$b)){echo "checked";} ?>>NBC<br />
    <input type="checkbox" name="d" value="http://www.abcnews.go.com" <?php if(in_array("http://www.abcnews.com",$b)){echo "checked";} ?>>ABC News<br />
     <input type="checkbox" name="e" value="http://www.usatoday.com" <?php if(in_array("http://www.usatoday.com",$b)){echo "checked";} ?>>USA Today<br />
      <input type="checkbox" name="f" value="http://www.msnbc.msn.com" <?php if(in_array("http://www.msnbc.msn.com",$b)){echo "checked";} ?>>MSNBC<br />
       <input type="checkbox" name="g" value="http://www.nytimes.com" <?php if(in_array("http://www.nytimes.com",$b)){echo "checked";} ?>>The New York Times<br />
        <input type="checkbox" name="h" value="http://www.ajc.com" <?php if(in_array("http://www.ajc.com",$b)){echo "checked";}?>>AJC<br />
         <input type="checkbox" name="i" value="http://www.chicagotribune.com" <?php if(in_array("http://www.chicagotribune.com",$b)){echo "checked";} ?>>Chicago Tribune<br />
          <input type="checkbox" name="j" value="http://www.washingtonpost.com" <?php if(in_array("http://www.washingtonpost.com",$b)){echo "checked";} ?>>Washington Post<br />
           <input type="checkbox" name="k" value="http://www.chrone.com" <?php if(in_array("http://www.chrone.com",$b)){echo "checked";} ?>>Chrone<br />
            <input type="checkbox" name="l" value="http://www.denverpost.com" <?php if(in_array("http://www.denverpost.com",$b)){echo "checked";} ?>>Denver Post<br />
             <input type="checkbox" name="m" value="http://www.knoxnews.com" <?php if(in_array("http://www.knoxnews.com",$b)){echo "checked";} ?>>Knox News<br />
              <input type="checkbox" name="n" value="http://www.foxnews.com" <?php if(in_array("http://www.foxnews.com",$b)){echo "checked";} ?>>Fox News<br />
               <input type="checkbox" name="o" value="http://www.skynews.com" <?php if(in_array("http://www.skynews.com",$b)){echo "checked";} ?>>Sky News<br />
  

What do you mean by it's still not working?  Are the check boxes just not being check?  No errors right?  If you don't know how to turn them on put this piece of code at the top of the page:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Also, are you sure there are values in the array?  Please print out the array by doing:

 

print_r($b);

I think you have to rethink how your creating the checkboxes. Here's a version that uses the power of PHP arrays correctly:

<?php
$urls = array('CNN'=>'cnn', 'BBC'=>'bbc', 'NBC'=>'nbc', 'ABC News'=>'abcnews', 'USA Today'=>'usatoday', 'MSNBC'=>'msnbc', 
'The New York Times'=>'nytimes', 'AJC'=>'ajc', 'Chicago Tribune'=>'chicagotribune', 'Washington Post'=>'washingtonpost',
'Chrone'=>'chrone', 'Denver Post'=>'denverpost', 'Knox News'=>'knoxnews', 'Fox News'=>'foxnews', 'Sky News'=>'skynews');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<title></title>
</head>

<body>
<form action="" method="post">
<?php
$tmp = array();
foreach ($urls as $n => $u) {
$chk = (isset($_POST['url_check'][$u]))?'checked':'';
$tmp[] = '<input type="checkbox" name="url_check[' . $u . ']" value="http://www.' . $u . '.com" ' . $chk . '>'. $n . '<br />';
}
echo implode("\n",$tmp) . "\n";
?>
<input type="submit" name="submit" value="Test It">
</form>  
<?php
if (isset($_POST['submit'])) echo '<pre>' . print_r($_POST,true) . '</pre>';
?>
</body>
</html>

 

Ken

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.