Link to home
Start Free TrialLog in
Avatar of adamn123
adamn123

asked on

Warning: mssql_result() [function.mssql-result]: Bad column offset specified in

I have no idea why I would be getting this error

Warning: mssql_result() [function.mssql-result]: Bad column offset specified in c:\Inetpub\wwwroot\assist_manager\inventorydata.php on line 79

Warning: mssql_result() [function.mssql-result]: Bad column offset specified in c:\Inetpub\wwwroot\assist_manager\inventorydata.php on line 84

Line 79
    $m .= mssql_result($resulta, $counter, $key);
Line 84
$devicecounter = $devicecounter + mssql_result($resulta, $counter, $key);

It populates my data and then just stops
<?php include('conn.php') ?>  
<?php include('open.php') ?>  
<html>
<head>
	<script type="text/javascript" src="sortable.js"></script>
</head>
<body>
 
<?php
 
$user = $_SERVER['LOGON_USER'];
$usernew = substr($user, 10);
 
 
//declare the SQL statement that will query the database
 
$query = "select Distinct m.ID, m.description
from conf_Inventory_Model m
      join Inventory i
        on m.ID=i.ID_Model
      join conf_Company c
        on i.ID_Company=c.ID
where c.Company='$usernew' ";
 
 
 
$result = mssql_query($query);
 
$a = array();
$b = array();
$c = array();
 
 
mt_srand((double)microtime()*1000000);
for($i = 0; $i < mssql_num_rows($result); $i++)
{
 
        $a[] = "Sum(Case when i.ID_Model=".mssql_result($result, $i, 'id')." then 1 else 0 end) as '". mssql_result($result, $i, 'id') ."'\n";
        $b[] = "<td><font face='verdana' size='1'><b>".mssql_result($result, $i, 'Description')."</b></font></td>"."\n";;
        $c[] =  mssql_result($result, $i, 'id');
 
}
 
$querya = "SELECT l.Location ," . implode(", ", $a) .
       " FROM Inventory I
         JOIN conf_Company C
         ON I.ID_Company=c.ID
         JOIN conf_Location l
         ON I.ID_Location=L.ID
         JOIN conf_Inventory_Model M
         ON I.ID_Model=M.ID
         WHERE C.Company='$usernew'
         GROUP BY L.Location";
  
$resulta = mssql_query($querya);
$ia = mssql_num_rows($resulta);
 
 
$ia = $ia -1;
$counter = 0;
$width = 350;
$m="";
 
while ( $counter <= $ia ) {
$countera = 0;
$devicecounter = 0;
$m .= '<tr>';
$m .= '<th><font face="verdana" size="1">';
$m .= mssql_result($resulta, $counter, 'location');
$m .= '</font></th>';
    $m .= "\n";
foreach($c as $key){
    $m .= '<td align="center"  width ="50"><font face="verdana" size="1">';
    $m .= '<a href="inventory2.php?location=';
    $m .= mssql_result($resulta, $counter, 'location');
    $m .= '&device=';
    $m .= mssql_result($result, $countera, 'Description');
    $m .= '">';
    $m .= mssql_result($resulta, $counter, $key);
    $m .= '</a>';
    $m .= '</font></td>';
    $m .= "\n";
$countera = $countera +1;
$devicecounter = $devicecounter + mssql_result($resulta, $counter, $key);
}
    $m .= '<td align="center"><font face="verdana" size="1">';
    $m .= $devicecounter;
    $m .= '</font></td>';
    $m .= '</tr>';
    $m .= "\n";
    $m .= "\n";
$counter = $counter +1;
}
$width = $width  + ($countera  * 50);
echo '<center>';
echo "\n";
echo '<Table class="sortable" border="1" width ="'.$width.'"';
echo "\n";
echo '<tr>';
echo '<th align="center" width ="300"><font face="verdana" size="1"><b>Location</b></font></th>';
echo "\n";
echo implode($b);
echo '<th align="center" width ="50"><font face="verdana" size="1"><b>Total</b></font></th>';
echo '</tr>';
echo "\n";
echo "\n";
echo  $m;
echo '</Table>';
echo "\n";
echo '</center>';
echo $counter;
 
//close the connection
mssql_close($dbhandle);
?>
</body>
</html>

Open in new window

Avatar of profya
profya
Flag of Sudan image

There is a problem with the field: location
Avatar of adamn123
adamn123

ASKER

Sorry I don't understand.
I would 3/4 of the way and stuffs
it does populate data and then just stops so it is reading the field
Means of code visualization is required, please add this:
echo "<pre>", print_r($key) , "<pre>";
to see what this array holds. Key array should contain field names, since the third argument of mssql_result method is the fieldname or number. You may need to revise this line:
$c[] =  mssql_result($result, $i, 'id');
I added echo "<pre>", print_r($key) , "<pre>"; at the bottom under

echo '</center>';
echo "<pre>", print_r($key) , "<pre>";

//close the connection
mssql_close($dbhandle);

It outputs
321
I am sorry, I meant to print_r ($c);
just before the line (45 I think):
$querya = "SELECT l.Location ," . implode(", ", $a) .......

Because this array contains the field numbers $key represents. Send me the output.
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 10 [6] => 15 [7] => 16 [8] => 17 [9] => 18 [10] => 19 [11] => 20 [12] => 21 [13] => 22 [14] => 23 [15] => 25 [16] => 26 [17] => 27 [18] => 28 [19] => 31 [20] => 32 )
I get outputs for [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 10 [6] => 15 [7] => 16 [8] => 17 [9] => 18 [10] => 19 [11] => 20 [12] => 21

It dies giving me resaults for
[13] => 22 [14] => 23 [15] => 25 [16] => 26 [17] => 27 [18] => 28 [19] => 31 [20] => 32
ASKER CERTIFIED SOLUTION
Avatar of profya
profya
Flag of Sudan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Almost have it
It is printing the data but I am getting

Warning: mssql_result() [function.mssql-result]: Bad row offset (21) in c:\Inetpub\wwwroot\assist_manager\inventorydata.php on line 81

Warning: mssql_result() [function.mssql-result]: Bad column offset specified in c:\Inetpub\wwwroot\assist_manager\inventorydata.php on line 83

Warning: mssql_result() [function.mssql-result]: Bad column offset specified in c:\Inetpub\wwwroot\assist_manager\inventorydata.php on line 88
<?php include('conn.php') ?>  
<?php include('open.php') ?>  
<html>
<head>
	<script type="text/javascript" src="sortable.js"></script>
</head>
<body>
 
<?php
 
$user = $_SERVER['LOGON_USER'];
$usernew = substr($user, 10);
 
 
//declare the SQL statement that will query the database
 
$query = "select Distinct m.ID, m.description
from conf_Inventory_Model m
      join Inventory i
        on m.ID=i.ID_Model
      join conf_Company c
        on i.ID_Company=c.ID
where c.Company='$usernew'  ";
 
 
 
$result = mssql_query($query);
 
$a = array();
$b = array();
$c = array();
 
 
mt_srand((double)microtime()*1000000);
for($i = 0; $i < mssql_num_rows($result); $i++)
{
 
        $a[] = "Sum(Case when i.ID_Model=".mssql_result($result, $i, 'id')." then 1 else 0 end) as '". mssql_result($result, $i, 'id') ."'\n";
        $b[] = "<td><font face='verdana' size='1'><b>".mssql_result($result, $i, 'Description')."</b></font></td>"."\n";;
 
//$c[] =  mssql_result($result, $i, 'id');
 
}
for($i=0; $i<=count($a); $i++)
{
	$c[]=$i+1;
}
$querya = "SELECT l.Location ," . implode(", ", $a) .
       " FROM Inventory I
         JOIN conf_Company C
         ON I.ID_Company=c.ID
         JOIN conf_Location l
         ON I.ID_Location=L.ID
         JOIN conf_Inventory_Model M
         ON I.ID_Model=M.ID
         WHERE C.Company='$usernew'
         GROUP BY L.Location";
  
$resulta = mssql_query($querya);
$ia = mssql_num_rows($resulta);
 
 
$ia = $ia -1;
$counter = 0;
$width = 350;
$m="";
 
while ( $counter <= $ia ) {
$countera = 0;
$devicecounter = 0;
$m .= '<tr>';
$m .= '<th><font face="verdana" size="1">';
$m .= mssql_result($resulta, $counter, 'location');
$m .= '</font></th>';
    $m .= "\n";
foreach($c as $key){
    $m .= '<td align="center"  width ="50"><font face="verdana" size="1">';
    $m .= '<a href="inventory2.php?location=';
    $m .= mssql_result($resulta, $counter, 'location');
    $m .= '&device=';
    $m .= mssql_result($result, $countera, 'Description');
    $m .= '">';
    $m .= mssql_result($resulta, $counter, $key);
    $m .= '</a>';
    $m .= '</font></td>';
    $m .= "\n";
$countera = $countera +1;
$devicecounter = $devicecounter + mssql_result($resulta, $counter, $key);
}
    $m .= '<td align="center"><font face="verdana" size="1">';
    $m .= $devicecounter;
    $m .= '</font></td>';
    $m .= '</tr>';
    $m .= "\n";
    $m .= "\n";
$counter = $counter +1;
}
$width = $width  + ($countera  * 50);
echo '<center>';
echo "\n";
echo '<Table class="sortable" border="1" width ="'.$width.'"';
echo "\n";
echo '<tr>';
echo '<th align="center" width ="300"><font face="verdana" size="1"><b>Location</b></font></th>';
echo "\n";
echo implode($b);
echo '<th align="center" width ="50"><font face="verdana" size="1"><b>Total</b></font></th>';
echo '</tr>';
echo "\n";
echo "\n";
echo  $m;
echo '</Table>';
echo "\n";
echo '</center>';
 
//close the connection
mssql_close($dbhandle);
?>
</body>
</html>

Open in new window

I did this
echo implode($c);
and I get
12345678910111213141516171819202122
I should only have a total of 21
I am 1 to many that is why I am getting the errors
Ok, this this line:
for($i=0; i<=count($a); $i++)

to

for($i=0; i<count($a); $i++)

i<= become i<

I hope it works fine after this.
Great work my friend!!!!!!!!!!!
You are welcome :)