Jump to content

Recommended Posts

Hey!

 

I got some help here: http://www.phpfreaks.com/forums/index.php/topic,223290.0.html

 

And here's my loop:

 

for($i = 1; $i <= $checks; ++$i){
   if ($site[$i] != ""){
      $foo[$i] = $site[$i];
   }
}

 

The problem is, is that if $site[1] is equal to "", then $foo[1] becomes "" ... I dont wont this to happen, I want $foo[1] to store the first $site[] which has a value which isnt "".

 

Thanks for all the help guys.

Link to comment
https://forums.phpfreaks.com/topic/130575-loop-help/
Share on other sites

if $site[1] is equal to "", then $foo[1] becomes "" ... I dont wont this to happen,

 

It doesn't happen.  Look at your code.  You only assign $foo[$i] = $site[$i] when $site[$1] IS NOT EQUAL to "".

 

if ($site[$i] != ""){
      $foo[$i] = $site[$i];
   }

Link to comment
https://forums.phpfreaks.com/topic/130575-loop-help/#findComment-677473
Share on other sites

I want $foo[1] to store the first $site[] which has a value which isnt "".

 

sounds like you need to explain what you want a little better then....

 

...maybe you meant this:

for($i = 1; $i <= $checks; ++$i){
   if (!empty($site[$i])){
      $foo[$i] = $site[$i];
   }
}

Link to comment
https://forums.phpfreaks.com/topic/130575-loop-help/#findComment-677494
Share on other sites

Still doesnt work, and sorry :(

 

Code(part of):

 

<?php
for($i = 1; $i <= $checks; ++$i){
   if (!empty($site[$i])){
      $foo[$i] = $site[$i];
   }
}

// set some variables
$user_pass = $_SESSION['user'];
$user_email = $_SESSION['user2']; 

$sql ="UPDATE users SET bg=\"$back\",box1=\"$foo[1]\",box2=\"$foo[2]\",box3=\"$foo[3]\",box4=\"$foo[4]\",box5=\"$foo[5]\",box6=\"$foo[6]\",box7=\"$foo[7]\",box8=\"$foo[8]\",box9=\"$foo[9]\",box10=\"$foo[10]\",box11=\"$foo[11]\",box12=\"$foo[12]\",box13=\"$foo[13]\",box14=\"$foo[14]\",box15=\"$foo[15]\" WHERE email=\"$user_email\" AND pass=( \"$user_pass\" )";
$query=mysql_query($sql, $link)
or die(mysql_error());
?>

 

If i have one box checked (please referr to post linked in first post), it is stored in the table column in relation to when it has been counted.

 

Help anyone? Thanks

Link to comment
https://forums.phpfreaks.com/topic/130575-loop-help/#findComment-677504
Share on other sites

ok, after doing a little testing, it appears that checkboxes that are unchecked are not added to the $_POST array at all. so, if you assign a $_POST[] that doesn't exist (of a checkbox that wasn't checked) to $site[$i], then $site[$i] would contain NULL (and you should probably get a warning). so maybe using is_null() instead of !empty() will work.

Link to comment
https://forums.phpfreaks.com/topic/130575-loop-help/#findComment-677538
Share on other sites

 

My loop code:

 

<?php
for($i = 1; $i <= $checks; ++$i){
   if (!isset($_POST['$i'])){
      $foo[$i] = $site[$i];
   }
}
?>

 

When one box is checked this displays:

 

array(15) { [1]=>  NULL [2]=>  string(18) "http://www.bbc.com" [3]=>  NULL [4]=>  NULL [5]=>  NULL [6]=>  NULL [7]=>  NULL [8]=>  NULL [9]=>  NULL [10]=>  NULL [11]=>  NULL [12]=>  NULL [13]=>  NULL [14]=>  NULL [15]=>  NULL } array(15) { [1]=>  NULL [2]=>  string(18) "http://www.bbc.com" [3]=>  NULL [4]=>  NULL [5]=>  NULL [6]=>  NULL [7]=>  NULL [8]=>  NULL [9]=>  NULL [10]=>  NULL [11]=>  NULL [12]=>  NULL [13]=>  NULL [14]=>  NULL [15]=>  NULL }

 

Thanks for any help.

 

Link to comment
https://forums.phpfreaks.com/topic/130575-loop-help/#findComment-677682
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.