Re: Undefined Index ...confusion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 7/23/09 9:24 AM, "Kyle Smith" <kyle.smith@xxxxxxxxxxxxxx> wrote:

Miller, Terion wrote:

I keep getting this error while trying to use the field 'ID' to pass in a url.. And it's odd because the query is pulling everything BUT the ID which is the first field...

code:
<a href="view.php?ID=<?php echo $_SESSION['fullRestaurantList']['ID']?>"><?php echo htmlspecialchars(stripslashes($_SESSION['fullRestaurantList'][$i]['name'])); ?>


We're going to need to know how the $_SESSION['fullRestaurantList'] gets populated.  Also, where do you define $i?  Is $i the ID?  Seemed like you've built an array of arrays and you may want $_SESSION['fullRestaurantList'][$i]['ID'], or just $i.  This is all speculation from the 2 lines of code I've seen though.

- Kyle



The full script is (I have my Entourage email settings on html so I hope this displays ok for you all---seems I've been told it turns into a mess in some views) :

<?php                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 // Check if page is set to show all                                    if(isset($_GET['show']) && $_GET['show'] == 'all')                                    {                                      unset($_SESSION['results']);                                      unset($_SESSION['searchname']);                                      unset($_SESSION['address']);                                                                                                               }                                                                        // Check if there was an empty search sent                                    if(isset($_SESSION['noVarsSent']))                                    {                                      echo "<p><b>No values were submitted for the search.</b></p>";                                      // Unset it so a reload of page doesn't redisplay the error                                      unset($_SESSION['noVarsSent']);                                      // unset($_SESSION['results']);                                    }                                                                                                            // Check if full list of restaurants has been created and stored yet                                    // Store full results in $_SESSION to limit database hits                                    if(!isset($_SESSION['fullRestaurantList']))                                    {                                      // List not grabbed yet, so run query and store in $_SESSION                                                                          //check for range                                    if (!(isset($rangenum)))                                      {                                      $rangenum = 1;                                      }                                      // Grab all restaurants in alphabetical order                                      $sql = "SELECT restaurants.ID, name, address, inDate, inType, notes, critical, cviolations, noncritical FROM restaurants, inspections WHERE restaurants.name != '' AND restaurants.ID = inspections.ID ORDER BY name;";                                       $result = mysql_query($sql) or die(mysql_error());                                                                        //trying to grab it by ranges from the db?                                         $rows = mysql_num_rows($result);                                      $page_rows = 100;                                      $last_row = ceil($rows/$page_rows);                                                                            if ($rangenum < 1)                                    {                                      $rangenum = 1;                                      }                                      elseif ($rangenum > $last_row)                                      {                                      $rangenum = $last_row;                                      }                                                                            //This sets the range to display in our query                                      $max = 'limit ' .($rangenum - 1) * $page_rows .',' .$page_rows;                                                                                                                                                        // Process all results into $_SESSION array                                                                            $position = 1;                                                                            while ($row = mysql_fetch_array($result))                                      {                                      $_SESSION['fullRestaurantList'][$position] = $row;                                      $position++;                                      }                                                                            $_SESSION['totalNumberOfRestaurants'] = $position;                                                                          }                                  ?>                                </td>                                                                                                    <td rowspan="5" width="400" height="180" valign="top">                                  <div style="vertical-align:text-top"                                  <h3></h3>                                  <img src="http://www.news-leader.com/graphics/pixelclear.gif"; width="400" height="1" />                                                                    </div>                                </td>                                                                                                  </tr>                              <tr>                                <td width="20%" align="right" height="30"><div class="admin_Caption">Name:</div></td>                                <td width="80%" height="30"><input name="searchname" type="text" size="30"                                <?php                                if(isset($_SESSION['searchname']))                                {                                  echo " value='" . $_SESSION['searchname'] . "'";                                }                                  ?>                                  >                                </td>                                                                                                                              </tr>                                                           <tr>                                <td width="20%" align="right" height="30"><div class="admin_Caption">Address:</div></td>                                <td width="80%"><input name="address" type="text" size="30"                                <?php                                if(isset($_SESSION['address']))                                {                                  echo " value='" . $_SESSION['address'] . "'";                                }                                  ?>                                  ></td>                              </tr>                                                                                            <tr>                                <td colspan="2" align="left"><input name="Submit" type="submit" value="Search">                                <br /><br />                                <a href="restaurants.php?show=all">Show all Restaurants</a>                                <br /><br />                                </td>                              </tr>                              <tr>                                <td colspan="3"><HR></td>                              </tr>                            </table>                            </form>                                                                                          <?php                                                        if(isset($_GET['Page']))                              $Page = $_GET['Page'];                            else                              $Page = 1;                                                                                                                                                                                $PerPage = 30;                            if(isset($_SESSION['numResults']))                            {                              $TotalPages = ceil($_SESSION['numResults']/$PerPage);                            }                            else                            {                              $TotalPages = 1;                            }                                                        $StartPage = ($Page - 1) * $PerPage;                                                        // Output table header                              ?>                                                            <TABLE WIDTH="100%" cellspacing="3" cellpadding="4">                                <TR>                                  <TD ALIGN="CENTER" width="50" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Name</B></FONT></TD>                                  <TD ALIGN="CENTER"  width="50" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Address</B></FONT></TD>                                  <TD ALIGN="CENTER" width="20" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Inspection Date</B></FONT></TD>                                  <TD ALIGN="CENTER" width="20" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Type</B></FONT></TD>                                  <TD ALIGN="CENTER"  width="120" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Notes</B></FONT></TD>                                  <TD ALIGN="CENTER" width="15" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B># Critical Violations</B></FONT></TD>                                  <TD ALIGN="CENTER" width="140" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B>Violations</B></FONT></TD>                                    <TD ALIGN="CENTER" width="15" VALIGN="TOP" BGCOLOR="#000000"><FONT size="-2" COLOR="#FFFFFF"><B># Non-Critical</B></FONT></TD>                                </TR>                              <?php                                                        // Control logic to determine if displaying results or not                            if(isset($_SESSION['results']))                            {                              // Output results                                                          if($_SESSION['results'] == "No results found")                              {                                // Query came back with nothing                                ?>                                <TR bgcolor="<?php echo $row_color ?>">                                  <td>                                <p>No results where found matching your criteria.</p>                                  </td>                                </tr>                                <?php                                                                }                              else                              {                                // There are results                                $ID= $_SESSION['results'][$i]['ID'];                                                                                                                                                                                      for($i = $StartPage + 1; $i < ($PerPage*$Page) && $i < $_SESSION['numResults']; $i++)                                {                                                                    $color1 = "#FFFFFF";                                  $color2 = "#EAEAEA";                                                              $row_color = ($i % 2) ? $color1 : $color2;                                  ?>                                  <TR bgcolor="<?php echo $row_color ?>">                                <TD><FONT SIZE="-2"><a href="view.php?ID=<?php echo ($_SESSION['results'][$i]['ID']); ?>"><?php echo htmlspecialchars(stripslashes($_SESSION['results'][$i]['name'])); ?></a></FONT></TD>                                <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['address']); ?></FONT></TD>                                <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['inDate']); ?></FONT></TD>                                <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['inType']); ?></FONT></TD>                                <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['notes']); ?></FONT></TD>                                <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['critical']);  ?></FONT></TD>                                <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['cviolations']);  ?></FONT></TD>                                      <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['results'][$i]['noncritical']);  ?></FONT></TD>                                        </TR>                                                                                                                        <?php                                }                                ?>                                </TABLE>                                <?php                                                            }                                                          }                            else                            {                              // No results, so output all restaurants sorted alphabetically                                                                                                                       // Else, list is already built.                                                                                                                                                                                                                                                                            for($i = $StartPage + 1; $i < ($PerPage*$Page) && $i < $_SESSION['totalNumberOfRestaurants']; $i++)                              {                                                                $color1 = "#FFFFFF";                                $color2 = "#EAEAEA";                                                              $row_color = ($i % 2) ? $color1 : $color2;                                ?>                                <TR bgcolor="<?php echo $row_color ?>">                                  <TD><FONT SIZE="-2"><a href="view.php?ID=<?php echo $_SESSION['fullRestaurantList']['ID']?>"><?php echo htmlspecialchars(stripslashes($_SESSION['fullRestaurantList'][$i]['name'])); ?></a></FONT></TD>                                  <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['address']); ?></FONT></TD>                                  <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['inDate']); ?></FONT></TD>                                  <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['inType']); ?></FONT></TD>                                  <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['notes']); ?></FONT></TD>                                  <TD align="center"><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['critical']);  ?></FONT></TD>                                  <TD><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['cviolations']);  ?></FONT></TD>                                      <TD align="center"><FONT SIZE="-2"><?php echo stripslashes($_SESSION['fullRestaurantList'][$i]['noncritical']);  ?></FONT></TD>                                </TR>                                                                                                                            <?php                              }                              ?>                              </TABLE>                              <?php                                                            // Calculate total number of pages                              $TotalPages = ceil($_SESSION['totalNumberOfRestaurants']/$PerPage);                                                          }                                                                                    // Output paging control                            // Only need to output this if there is more than 1 page of results                            if ($TotalPages > 1)                            {                                                            echo "<hr /> \n <p>Click on the following links for more pages of results</p> \n <p>";                                                            if ($Page != 1)                              {                                // If on first page, no need for Previous Page button                                echo "<a href='restaurants.php?Page=";                                echo $Page-1;                                echo "'><< Previous</a> ";                              }                                                              for($i = 1; $i <= $TotalPages; $i++)                              {                                                                if($i == $Page)                                {                                  // Outputting link for current page - doesn't need to be a link                                  echo "$i ";                                }                                else                                {                                  // Outputting link for other pages - needs to be a link                                  echo "<a href='restaurants.php?Page=$i'>$i</a> ";                                }                                                              }                                                            if ($Page != $TotalPages)                              {                                // If on last page, no need for Next Page button                                echo "<a href='restaurants.php?Page=";                                echo $Page+1;                                echo "'>Next >></a> ";                              }                                                          }                                                          ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux