Solved

Notice: Undefined offset: 4

Posted on 2013-01-27
5
875 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
Comment Utility
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
Comment Utility
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
Comment Utility
$num_columns = mysql_num_fields($ct);
while ($j < $num_columns){ 

Open in new window

0
 

Author Comment

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

Expert Comment

by:sedgwick
Comment Utility
thank you.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now