Need a ‘second pair of eyes’ to check code..

Archived from the Xataface Users forum.

danw — Mon Jun 15, 2009 7:43 am

I need a pair of eyes to double check. Code works on 1 table, not the other.

I can SEE RESULTS from the “sysFunction” - - but I only see “. ()” for the sysStatus.

Code seems IDENTICAL.

==================table layouts ===================

sysFunction

id

function

sysStatus

id

status

both id = smallints

both fuction & status varchars

________________ ~/actions _______________

browse_by function = WORKS

Code: Select all
`<?php
  class actions_browse_by_function  {

  function handle(&$params){

  $sql = “select id as func_id, function as func_function from sysFunction order by function”;

  $res = mysql_query($sql, df_db());
  $functions = array();
   while ( $row = mysql_fetch_assoc($res) ){
  print_r($row);

    $sql2 = “select count(*) as num from Systems where function rlike ‘[[:<:]]”.$row[‘func_id’].”[[:>:]]’”;
    $res2 = mysql_query($sql2, df_db());
            list($num) = mysql_fetch_row($res2);
            if ( $num ){

    $functions[] = array(‘name’=>$row[‘func_function’],
                                        ‘id’=>$row[‘func_id’],
                                    ‘num’=>$num);
            }
            @mysql_free_result($res2);
        }
        @mysql_free_result($res);
        $num_funcs = count($functions);
        $per_column = ceil($num_funcs/6);

df_display(array(‘functions’=>$functions, ‘per_column’=>$per_column), ‘browse_by_function.html’);
    }
}

?>`

_______________ browse by status _________ DOES NOT WORK

Code: Select all
`php

class actions_browse_by_status {
  function handle(&$params){

  $statii = array();

  $sql = “select id as stat_id, status as stat_status from sysStatus order by id”;
  $res      = mysql_query($sql, df_db());

   while ( $row = mysql_fetch_assoc($res) ){
print_r($row);

    $sql2 = “select count(*) as num from Systems where status rlike  ‘[[:<:]]”.$row[‘stat_id’].”[[:>:]]’”;
    $res2 = mysql_query($sql2, df_db());

            list($num) = mysql_fetch_row($res2);

print “NUM: $num
”;

            if ( $num ){

                $statii[] = array(‘name’=>$row[‘stat_status’],
                                  ‘id’=>$row[‘stat_id’],
                                  ‘num’=>$num);
            }
            @mysql_free_result($res2);
        }
        @mysql_free_result($res);

        $num_status = count($statii);
        $per_column = ceil($num_status/4);

df_display(array(‘statii’=>$statii, ‘per_column’=>$per_column), ‘browse_by_status.html’);

    }

}
?>`

the print_r($row) & NUM shows the following for “sysStatus”:
Array ( [stat_id] => 1 [stat_status] => Production ) NUM: 1790
Array ( [stat_id] => 2 [stat_status] => In-Storage ) NUM: 415
Array ( [stat_id] => 3 [stat_status] => No-Automation ) NUM: 225
Array ( [stat_id] => 4 [stat_status] => Test-Sandbox-Lab ) NUM: 79
Array ( [stat_id] => 5 [stat_status] => Unassigned ) NUM: 151
Array ( [stat_id] => 6 [stat_status] => Parts-Salvage ) NUM: 4
Array ( [stat_id] => 7 [stat_status] => Deleted ) NUM: 55

________________ ~/templates _______________

( for function )

‘browse_by_function.html’ - - WORKS

Code: Select all
`use_macro file=”Dataface_Main_Template.html”}

{fill_slot name=”main_section”}

Browse Systems by Function

  {foreach from=$functions item=function key=ctr}
   {if $ctr%$per_column == 0}
   {if $ctr>0}</ul></div>{/if}<div style="width: 15%; float: left; margin: 0; padding: 0; padding-top: 1em; "><ul>
   {/if}

  • {$function.name} ({$function.num})
  •         {/foreach}
            </ul></div>
            <div style="clear: both"/>
        {/fill_slot}
    {/use_macro}`

    =============== for status ===========
    ‘browse_by_status.html’ - Don’t see counts or names etc

    Code: Select all
    `use_macro file=”Dataface_Main_Template.html”}
    {fill_slot name=”main_section”}

    Browse Systems by Status

      {foreach from=$statii item=status key=ctr}
       {if $ctr%$per_column == 0}

      {if $ctr>0}</ul></div>{/if}<div style="width: 15%; float: left; margin: 0; padding: 0; padding-top: 1em; "><ul>
       {/if}

  • {$stat.status}({$num})
  •         {/foreach}
            </ul></div>
            <div style="clear: both"/>
        {/fill_slot}
    {/use_macro}`

    SO, I’m getting data, just doesn’t seem to be passing? Anybody see anything?

    In advance, thanks

    dan

    ========= END POST LAST LINE =========


    silma — Mon Jun 15, 2009 9:39 am

    The only difference i see is there :

    =============== for status ===========

    ‘browse_by_status.html’ - Don’t see counts or names etc

    Code: Select all
    `use_macro file=”Dataface_Main_Template.html”}
    {fill_slot name=”main_section”}

    Browse Systems by Status

      {foreach from=$statii item=status key=ctr}
       {if $ctr%$per_column == 0}

      {if $ctr>0}</ul></div>{/if}<div><ul>
       {/if}

  • {$stat.status}({$num})
  •         {/foreach}
            </ul></div>
            <div>
        {/fill_slot}
    {/use_macro}`

    ({$num}) should maybe be ({$statii.num})</li>

    Hope this help,

    Silma


    danw — Mon Jun 15, 2009 11:56 am

    Go figure: working: Had ‘name’ instead of ‘status’

    WORK’s: {$status.name} ({$status.num})</li>

    DOES NOT WORK:

    {$stat.status}({$num})</li>

    cheers!

    dan