Solved

Notice: Undefined offset: 4

Posted on 2013-01-27
5
964 Views
Last Modified: 2016-03-18
I have a small php page in sugarcrm project:
I am getting following error:
Notice: Undefined offset: 4 in C:\Projects\SugarCE-Full-6.5.9\modules\ppi_reports\index.php on line 47
echo $row[$i] . '          ';   // error this line 47
Display on screen:
Monthly New Preliminary Investigations Report
Menu: 'db:' . sugarcrm . ' tbl:' . dyn_menu
Cols:id label link_url parent_id Rows:36
1
Edit Admin
/index_paginated2.php
1
Notice: Undefined offset: 4 in C:\Projects\SugarCE-Full-6.5.9\modules\ppi_reports\index.php on line 47
Data in dyn_menu table:
 edit      id      label      link_url      parent_id
 edit      1      Edit Menu             0
 edit      2      Edit Admin             0
 edit      3      View Pagination      /index_paginated2.php      1
 edit      4      Add New      /index_new.php      1
 edit      5      View Pagination      ../../phpMaker/AdminTable/index_paginated.php      2
 edit      6      Add New      ../../phpMaker/AdminTable/index_new.php      2
For clarity the full code is below:
Thanks in advance for any help given.
<?php
//'dbconfig' =>array ('db_host_name' => 'localhost','db_host_instance' => 'SQLEXPRESS','db_user_name' => 'root','db_password' => 'H6web97!','db_name' => 'sugarcrm','db_type' => 'mysql','db_port' => '','db_manager' => 'MysqliManager',),
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$report_title = "Monthly New Preliminary Investigations Report";
$sql = "SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC";
$sql2 = "No entry point ";
$db_name= $sugar_config['dbconfig']['db_name'];
$setup_db_host_name = $sugar_config['dbconfig']['db_host_name'];
$setup_db_admin_user_name = $sugar_config['dbconfig']['db_user_name'];
$setup_db_host_instance = $sugar_config['dbconfig']['db_host_instance'];
$setup_db_admin_password = $sugar_config['dbconfig']['db_password'];
$table_name =  'dyn_menu';
echo "<h2>$report_title</h2>";
 if (!sugarEntry)
   {
    echo "<table width=100% cellspacing=0 cellpading=0>";
    echo "<tr>";
    echo "<td>$sql2</td>";
    echo "</tr>";
    echo "</table>";
   die('<br/>No Menu:<br/>' . mysql_error());
   }
   else
   {
echo "Menu: 'db:' . $db_name . '          tbl:' . $table_name<br/>";
$link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
mysql_select_db('information_schema');
$qu="SELECT column_name FROM information_schema.columns WHERE table_schema = '".$db_name."' AND table_name = '".  $table_name."'";
$ct =mysql_query($qu,$link);
//$cols= '';
$colsDrop = array();
echo 'Cols:';
while($row = mysql_fetch_assoc($ct)){
$colsDrop[] =$row['column_name'];
echo $row['column_name'] . '                         ';
}
$i = 0;
$link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
mysql_select_db("$db_name");
//$qu = "SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC";
$qu="SELECT * FROM $table_name ";
$ct =mysql_query($qu,$link);
$numRows = mysql_num_rows($ct);
echo 'Rows:' . $numRows . '<br/>';
while ($i < mysql_num_rows($ct)) {
$row = mysql_fetch_row($ct);
echo $row[$i] . '          ';   // error this line 47
$i++;
echo '<br/>';
}
    //return $colsDrop;

   }
?>
0
Comment
Question by:homeshopper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824123
please post the code between code tags, makes it easier to review it


echo $row[$i] . '          ';   // error this line 47
make sure $i < $row array size
usually that is what the error indicates.
0
 

Author Comment

by:homeshopper
ID: 38824234
Thanks, nearly got it working. new code as follows:
$i = 0;
$link = @mysql_connect($setup_db_host_name, $setup_db_admin_user_name, $setup_db_admin_password);
mysql_select_db("$db_name");
//$qu = "SELECT id, label, link_url, parent_id FROM dyn_menu ORDER BY parent_id, id ASC";
$qu="SELECT * FROM $table_name ";
$ct =mysql_query($qu,$link);
$numRows = mysql_num_rows($ct);
echo 'Rows:' . $numRows . '<br/>';
while ($i < mysql_num_rows($ct)) {
$row = mysql_fetch_row($ct);
$j = 0;
while ($j < 3){  // line 48 needs change
echo $row[$j] . '          '; 
$j++;  
}
$i++;
echo '<br/>';
}

Open in new window

while ($j < 3){  // line 48 needs change
how can I put number of columns as variable instead of '3' ?
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38824266
$num_columns = mysql_num_fields($ct);
while ($j < $num_columns){ 

Open in new window

0
 

Author Comment

by:homeshopper
ID: 38824275
Thanks for the help, I'll award points.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38824283
thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question