Solved

Notice: Undefined offset: 4

Posted on 2013-01-27
5
979 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

628 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