Hello everyone, I'm trying to make a script that checks values, to see if a value is in use or not. If all the values are in use, it displays a message. If any of the values are not in use, it does not display a message. Here is what I have created - while($content = mysql_fetch_array($display25)) $content1 = $content['h1']; $content2 = $content['h2']; $content3 = $content['h3']; $content4 = $content['h4']; $content5 = $content['h5']; $content6 = $content['h6']; $content7 = $content['h7']; $content8 = $content['h8']; $content9 = $content['h9']; $content10 = $content['h10']; $content11 = $content['h11']; $content12 = $content['h12']; $content13 = $content['h13']; $content14 = $content['h14']; $content15 = $content['h15']; $content16 = $content['h16']; $content17 = $content['h17']; $content18 = $content['h18']; $content19 = $content['h19']; $content20 = $content['h20']; $content21 = $content['h21']; $content22 = $content['h22']; $content23 = $content['h23']; $content24 = $content['h24']; if ($content1=="BLANK") {} else { if ($content2=="BLANK") {} else { if ($content3=="BLANK") {} else { if ($content4=="BLANK") {} else { if ($content5=="BLANK") {} else { if ($content6=="BLANK") {} else { if ($content7=="BLANK") {} else { if ($content8=="BLANK") {} else { if ($content9=="BLANK") {} else { if ($content10=="BLANK") {} else { if ($content11=="BLANK") {} else { if ($content12=="BLANK") {} else { if ($content13=="BLANK") {} else { if ($content14=="BLANK") {} else { if ($content15=="BLANK") {} else { if ($content16=="BLANK") {} else { if ($content17=="BLANK") {} else { if ($content18=="BLANK") {} else { if ($content19=="BLANK") {} else { if ($content20=="BLANK") {} else { if ($content21=="BLANK") {} else { if ($content22=="BLANK") {} else { if ($content23=="BLANK") {} else { if ($content24=="BLANK") {} else { echo "There are currently no spots available for $result"; }}}}}}}}}}}}}}}}}}}}}}} } PHP: Now, if all the spots are "BLANK", it does not show the message (There are currently no spots available for $result). However, if even one of the spots is not blank, it shows the message. I want it so that it only shows the message if all of the slots are not blank. Thanks!
stick them all in the same if statement if($content1=="BLANK" || $content2=="BLANK" || $content3=="BLANK" ... Code (markup): || means "or" if you were wondering
I changed it to while($content = mysql_fetch_array($display25)) $content1 = $content['h1']; $content2 = $content['h2']; $content3 = $content['h3']; $content4 = $content['h4']; $content5 = $content['h5']; $content6 = $content['h6']; $content7 = $content['h7']; $content8 = $content['h8']; $content9 = $content['h9']; $content10 = $content['h10']; $content11 = $content['h11']; $content12 = $content['h12']; $content13 = $content['h13']; $content14 = $content['h14']; $content15 = $content['h15']; $content16 = $content['h16']; $content17 = $content['h17']; $content18 = $content['h18']; $content19 = $content['h19']; $content20 = $content['h20']; $content21 = $content['h21']; $content22 = $content['h22']; $content23 = $content['h23']; $content24 = $content['h24']; if ($content1=="BLANK" || $content2=="BLANK" || $content3=="BLANK" || $content4=="BLANK" || $content5=="BLANK" || $content6=="BLANK" || $content7=="BLANK" || $content8=="BLANK" || $content9=="BLANK" || $content10=="BLANK" || $content11=="BLANK" || $content12=="BLANK" || $content13=="BLANK" || $content14=="BLANK" || $content15=="BLANK" || $content16=="BLANK" || $content17=="BLANK" || $content18=="BLANK" || $content19=="BLANK" || $content20=="BLANK" || $content21=="BLANK" || $content22=="BLANK" || $content23=="BLANK" || $content24=="BLANK") {} else { echo "There are currently no spots available for $result"; } PHP: But I still have the exact same problem :/
$contentList = array( 1 => $content['h1'], 2 => $content['h2'], 3 => $content['h3'], 4 => $content['h4'], 5 => $content['h5'], 6 => $content['h6'], 7 => $content['h7'], 8 => $content['h8'], 9 => $content['h9'], 10 => $content['h10'], 11 => $content['h11'], 12 => $content['h12'], 13 => $content['h13'], 14 => $content['h14'], 15 => $content['h15'], 16 => $content['h16'], 17 => $content['h17'], 18 => $content['h18'], 19 => $content['h19'], 20 => $content['h20'], 21 => $content['h21'], 22 => $content['h22'], 23 => $content['h23'], 24 => $content['h24'] ); $displayMessage = true; foreach ($contentList as $item) { if ($item == 'BLANK') { $displayMessage = false; break; } } if ($displayMessage == true) { // show message } PHP:
you can use the power of loops and variable variables: $fieldsCount = 24; $inUse = false; $counter = 0; $content[1]='BLANK'; $content[2]='BLANK'; $content[3]='Test'; $content[4]='BLANK'; /* ... */ for($counter =1; $counter <= $fieldsCount; $counter +=1) { if($content{$counter} != "BLANK") { $inUse= true; break; } } if($inUse) { echo 'This field at least is not "BLANK": '.$counter; } PHP: