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
Share on other sites

It gives the value of the array

Array ( [1] => CA789456 [2] => CA654321) 

It does that for if I have no bookings and if I do. And it is giving the right values and the right amount of values. Those values are registration plate numbers.

Link to comment
Share on other sites

So I have figured out this is where the problem lies. I give available the values with this

 

$available = array_diff($bikes,$booked); 

 

I use that when there are bookings. When I print_r that it only starts at array[1]?

 

Thanks

Link to comment
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.