Jump to content

prepared statement....results from many tables


jimfog

Recommended Posts

I am using a prepared statement to bring results from more that 2 tables.

One of the tables lists servicenames with prices and duration....each table row corresponds to one service....so:

 while ($stmt->fetch())                      {                    $serviceslist[]=array('service'=>$servicename,'price'=>$price,'serviceID'=>$serviceID,'duration'=>$duration);                     }

The problem is that I need to fetch some data that reside to another table....regarding if the prices of the services should be visible or not....so I do something like this:


while ($stmt->fetch())
{
$serviceslist[]=array('service'=>$servicename,'price'=>$price,'serviceID'=>$serviceID,'duration'=>$duration);
$serviceslist['prices']=$prices_visibility;
}

and then to print to the browser:

  for($i = 0, $size = count($serviceslist); $i < $size; ++$i) {?><input class='services' data-service="<?php  {echo $serviceslist[$i]['serviceID'];} ?>" size ='40' value="<?php  {echo $serviceslist[$i]['service'];} ?>" type="text" name="<?php echo 'service'.$i ?>"> //line 258       <input class='price' size ='3' value="<?php  {echo $serviceslist[$i]['price'];} ?>" type="text" name="<?php echo 'price'.$i ?>">                        <input class='duration' size ='3' value="<?php  {echo $serviceslist[$i]['duration'];} ?>" type="text" name="<?php echo 'duration'.$i ?>">λεπτά                   <?php }?> 

the problem is that I get a warning:

<br /><b>Notice</b>: Undefined offset: 2 in <b>C:Apache24htdocsAppointmentsAdministratorprofile.php</b> on line <b>258</b><br />

 

Obvioulsy adding to the array the prices index creates a problem with the loop...but what that might be?

 

 

Link to comment
Share on other sites

Use print_r on $serviceslist to see the problem.

within the loop or outside it...

Link to comment
Share on other sites

here is what get printed(print_r is used outside of the loop):

Array ( [0] => Array ( [service] => haircut [price] => 65.00 [serviceID] => 19 [duration] => 20 ) [price] => 1 [1] => Array ( [service] => μανικιουρ [price] => 70.00 [serviceID] => 20 [duration] => 20 ) )

I think [price] is creating the issue here...

So the question becomes how to integrate prices to the array without triggering such a notice.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...