0

Wasn't sure what exactly to search for so apologies if this has been covered elsewhere..

Basically I have Bulkhead1, Bulkhead2, Bulkhead3 etc and I'm trying to save space by adding 1 each time but I'm going wrong somewhere! :(

Something is going wrong here - $row['Bulkhead"'.$it.'"']

$i=1;
while($x= mysqli_fetch_array($y)) { 
$bh = $row['Bulkhead"'.$it.'"'];
}
$i++;
1
  • shouldnt it be while($row = mysqli_fetch_array($)) { $bh = $row['Bulkhead"'.$it.'"']; } Commented Sep 16, 2016 at 14:57

3 Answers 3

1

try; $bh = $row['Bulkhead'.$i];

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! Been doing my head in!! Probably something I would've solved if it wasn't late afternoon on a Friday. For some reason I didn't think you could go outside the ' '.. Anyway - Thanks :)
1

I think that the double quotes are misused, also you are using $i and $it, is it a typo?

$i=1;
while($x= mysqli_fetch_array($y)) { 
    $bh = $row["Bulkhead$i"];
    $i++;
}

Comments

0

I don't really understand what you want but I will try to fix your code:

    $i=1;
    while($x= mysqli_fetch_array($y))
    { 
   echo 'Bulkhead'. $i;
   $i++;
    }

Or as an array:

$bh  = array ();
$i=1;
while($x= mysqli_fetch_array($y))
{ 
   $ bh[ ]= 'Bulkhead'. $i;
   $i++;
}

If I get you wrong, try to explain your question better.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.