Jump to content

[SOLVED] Wierd prob with arrays


peuge

Recommended Posts

Hi all,

 

I have a booking form and am sending data entered by the user and also collected from a database about availability.

 

On my page where I insert the data into the db I have the following code (and more but that's working fine)

The code below is just for testing purposes so I know what is and what is not being sent.

 

//This displays the number of available bikes that are sent to the booked.php page
echo '<br/>The available bikes that are sent <br/>';
$avail1 = urldecode($avail);
$available = unserialize($avail1);

foreach ($available as $jim){
  echo $jim.'<br/>';
}

//This displays the number of bikes the user selected and is sent to the booked.php page
echo 'Them amnt that is sent: '.$amnt.'<br/>';

//This is where I am going to have my SQL insert statement.
for ($i=0;$i<$amnt;$i++){
  echo $available[$i];
  echo '<br/>';}

 

 

I am not getting any errors or anything. The problem is that when there are already bookings and I choose to take 1 bike for rental the for loop above does not work and does not show anything. Everything above the for loop works fine all the time. If I choose to take more than 1, for example 3 bikes, then it only displays two bikes (in the for loop). Now if there are no bookings (i.e. all the bikes are available) then it works absolutely fine. It has nothing to do with my SQL queries as it is getting the right data, I can see that because of what it is showing me from above. For some reason it seems that when there are no bookings that $available[0] exists whereas when there are bookings $available[0] does not exist?

 

Any help much appreciated

 

Thnks

Link to comment
https://forums.phpfreaks.com/topic/121100-solved-wierd-prob-with-arrays/
Share on other sites

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.