Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Notice: Undefined offset: 4

Posted on 2013-01-27
5
Medium Priority
?
1,041 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:Meir Rivkin
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:
Meir Rivkin earned 2000 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:Meir Rivkin
ID: 38824283
thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

963 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