Solved

Notice: Undefined offset: 4

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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