intval()

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
egoo
-


Joined: 22 Jan 2008
Posts: 16

PostPosted: Sat Jun 21, 2008 2:25 pm    Post subject: intval() Reply with quote

When I have compiled the script below it appears the following PHP Notice:
Code:

<html>
<head>
  <title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
  //Read in the entire file.
  //Each order becomes an element in the array
  $orders= file("orders.txt");
  // count the number of orders in the array
  $number_of_orders = count($orders);
  if ($number_of_orders == 0)
  {
    echo '<p><strong>No orders pending.
            Please try again later.</strong></p>';
  }
  echo "<table border=1>\n";
  echo '<tr><th bgcolor="#CCCCFF">Order Date</th>
            <th bgcolor="#CCCCFF">Tires</th>
            <th bgcolor="#CCCCFF">Oil</th>
            <th bgcolor="#CCCCFF">Spark Plugs</th>
            <th bgcolor="#CCCCFF">Total</th>
            <th bgcolor="#CCCCFF">Address</th>
         <tr>';
  for ($i=0; $i<$number_of_orders; $i++)
  {
    //split up each line
    $line = explode( "\t", $orders[$i] );
    print_r($line);
    // keep only the number of items ordered
    $line[1] = intval( $line[1] );//Undefined offset:1
    $line[2] = intval( $line[2] );//Undefined offset:2
    $line[3] = intval( $line[3] );//Undefined offset:3
    // output each order
    echo "<tr><td>$line[0]</td>
                <td align='right'>$line[1]</td>
                <td align='right'>$line[2]</td>
                <td align='right'>$line[3]</td>
                <td align='right'>$line[4]</td>//Undefined offset:4
                <td>$line[5]</td>//Undefined offset:5
            </tr>";
 }
  echo "</table>";

?>
</body>
</html>


Please, correct it in order to eliminate PHP Notice. Thank you in advance


Last edited by egoo on Mon Jun 23, 2008 5:00 pm; edited 2 times in total
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Sun Jun 22, 2008 6:59 pm    Post subject: Reply with quote

Why don't you show us a sample line or two from orders.txt?
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
egoo
-


Joined: 22 Jan 2008
Posts: 16

PostPosted: Mon Jun 23, 2008 4:51 pm    Post subject: orders.txt Reply with quote

orders.txt
15:42, 20th April 4 tires 1 oil 6 spark plugs $434.00 22 Short St, Smalltown
15:43, 20th April 1 tires 0 oil 0 spark plugs $100.00 33 Main Rd, Newtown
15:43, 20th April 0 tires 1 oil 4 spark plugs $26.00 127 Acacia St, Springfield
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Tue Jun 24, 2008 1:48 pm    Post subject: Reply with quote

Are the fields in orders.txt separated by tabs? That's how they're being parsed. Or do tabs just not show up in your post?
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
egoo
-


Joined: 22 Jan 2008
Posts: 16

PostPosted: Fri Jun 27, 2008 6:10 pm    Post subject: auto parts Reply with quote

why it is appeared:
[img]
Bob's Auto Parts

Customer Orders
Order Date Tires Oil Spark Plugs Total Address

15:42, 20th April
15:43, 20th April
15:43, 20th April
[/img]
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group