Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > Just not getting it--need help with Generate Report function
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 12th June 13:35
ward
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


Greetings.

I'm really under the gun here and could use some help. I've been
spending too much time racking my brains trying to figure this
function out. I've tried hacking away at other scripts but I think
this one is just a tad more complicated and requires expert advice.

Here is what I want to accomplish:

Provide a webpage that'll allow the user to select records to be
retrieved from:
a. certain groups
b. desired fields.

In other words, I'd like to like the user select Group A, Group B,
and/or Group C AND show Fields A, C, D, F.

As for the process, I see three steps:

1) generate form
2) extract data from arrays to run the query
3) present the report

The file I'm showing below has modified by someone who said I needed
to use PEAR. Well, I don't think it's an option so I was hoping there
would be a non-PEAR solution.

What I get now is the form coming up, but nothing happens when I hit
the "Generate" button. Hmmmm....I would think at least something
would happen to generate an error.

Thoughts/suggestions would be greatly appreciated.

Thanks.

Ward

<?PHP

// Begin the page now.
$page_title = 'Generate Report';
include ('./includes/header.html');

$mdb = new mdb;
$report = false;

// Check if the form has been submitted.
switch ($_REQUEST['submit']){
case "Generate":

// first extract group
$query = "";
if(count($_REQUEST['sel_groups']) > 0){
$wval = array ();
foreach($_REQUEST['sel_groups'] as $k => $v){
$wval[] = "groups_id='{$v}'";
}

//extract the columns
$scols = array ();
if(count($_REQUEST['sel_cols]']) > 0){
foreach($_REQUEST['sel_cols'] as $k => $v){
$scols[] = "{$v}";
}

//building query
$where = join(' AND ', $wval);
$sel_cols = join(',', $scols);
require_once ('includes/mysql_connect.php'); //
Connect to the db.
$query = "SELECT {$sel_cols} FROM tasks WHERE {$where}";

if($db->db_dbArray($DB, $query)){
$report = (count($db->_db[data]) > 0);
}
}
}
break;

default:

}

if($report){
?>

<table height="0%" width="0%" cellpadding="3" cellspacing="1"
align="center" bgcolor="#000000">
<tr bgcolor="#cccccc" align="center">
<? foreach($_REQUEST['sel_groups'] as $k => $v){?>
<td><b><?= $v ?></b></td>
<? } ?>
</tr>

<? for($i=0;$i<count($db->_db[data]);$i++){ ?>
<tr bgcolor="#ffffff" align="center">
<? foreach($_REQUEST['sel_groups'] as $k => $v){?>
<td><?= $db->_db[data][$i][$v] ?></td>
<? } ?>
</tr>
<?}?>
</table>

<?
}

echo '<fieldset><legend>Generate Report</legend>

<form action="generate_report_v11.php" method="post">

<CENTER>
<TABLE BORDER="1" cellpadding="5" cellspacing="5">
<TR>
<TD rowspan="2" valign="bottom"><strong>Select ICAO
Group(s)</strong></TD>
<TD colspan="2"><strong>Select Columns</strong></TD>
</TR>
<TR>
<TD><strong>ICAO Work Programme</strong></TD><TD><strong>SME
Input</strong></TD>
</TR>
<TR>
<TD align="left" valign="top">';

require_once ('includes/mysql_connect.php'); // Connect to the
db.
$query = "SELECT * FROM groups ORDER BY groups_id ASC";
$result = @mysql_query ($query);

while($rows = mysql_fetch_array($result))
{
$id = $rows['groups_id'] ;
$name = $rows['groups_name'];

echo "<input name=\"sel_groups[]\" type=\"checkbox\"
value=\"$id\">$name<BR>\n";
}


echo '
</TD>
<TD align="left" valign="top">
<input name="sel_cols[]" type="checkbox" value="groups_name">
Group Name<BR>
<input name="sel_cols[]" type="checkbox"
value="task_desc">Description of Task<BR>
<input name="sel_cols[]" type="checkbox" value="task_id">Task
No.<BR>
<input name="sel_cols[]" type="checkbox"
value="task_compdate">Estimated Completion Date<BR>
<input name="sel_cols[]" type="checkbox"
value="task_source">Source &amp; References<BR>
<input name="sel_cols[]" type="checkbox" value="task_note">ICAO
Note on Progress<BR>
</TD>
<TD align="left" valign="top">
<input name="sel_cols[]" type="checkbox"
value="task_usposition">U.S. Position<BR>
<input name="sel_cols[]" type="checkbox"
value="task_exp_outcome">Expected Outcome<BR>
<input name="sel_cols[]" type="checkbox"
value="task_outcome">Outcome<BR>
<input name="sel_cols[]" type="checkbox"
value="task_usaction">U.S. Action<BR>
<input name="sel_cols[]" type="checkbox"
value="task_probs_issues">Problems &amp; Issues<BR>
<input name="sel_cols[]" type="checkbox"
value="task_smecomments">Notes/Comments<BR>
</TD>


</TR>

</TABLE></CENTER>

<input name="submit" type="submit" value="Generate">

</form>

</fieldset>';

include ('includes/footer.html')
?>
  Reply With Quote


  sponsored links


2 12th June 13:35
robert
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


|
| I'm really under the gun here and could use some help. I've been
| spending too much time racking my brains trying to figure this
| function out. I've tried hacking away at other scripts but I think
| this one is just a tad more complicated and requires expert advice.
<snip>

you really get an object back from:

$mdb = new mdb;

i thought it had to be:

$mdb = new mdb();

anyway, two of these will always be correlated...the other defines the
relationship:

time, cost, quality.

obviously you have selected "time" as a key factor. looking at the code you
want fixed *and* the fact that you are posting it here for others to fix, i
assume that quality is not of prime importance. that leaves cost. until you
figure it out yourself or pay someone to fix it, quality will continue to
suffer since you're investing very little to get a timely outcome.

i'd like to know if we would get your paycheck as you're asking us to do
your work?
  Reply With Quote
3 12th June 14:06
ward
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


Robert,

I appreciate the first part of your response but I'm rather confused
about the second part.

I've purchased (so I have spent a good amount of money). But this one
is throwing me a curve

I wasn't asking anyone to write anything from scratch...just tell me
what part(s) I need to explore.

BTW, I am an airline pilot (a subject I could be considered an
"expert") and have been called by numerous friends and acquaintances
asking for my opinion on things for personal *and* professional
reasons. I have never asked for anyone's paycheck for trying to be
helpful.

Ward

On Wed, 10 May 2006 13:05:51 -0500, "robert"
<ab@no.spam-alama-ding-dong> wrote:
  Reply With Quote
4 12th June 14:06
ward
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


Well Robert, I found one small ommission that didn't allow the page to
load properly. But when I added the (), this is the error I received.


Fatal error: Cannot instantiate non-existent class: mdb in
/generate_report.php on line 7

I'm going to look it up and see what I can learn but thought I would
pass it along in case you had other suggestions.

Thanks.

Ward
  Reply With Quote
5 12th June 14:06
robert
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


|
| I appreciate the first part of your response but I'm rather confused
| about the second part.
|
| I've "written" a good bit of PHP...have a whole site running it.
| Granted it was more hacking away at examples in the numerous books
| I've purchased (so I have spent a good amount of money). But this one
| is throwing me a curve

i'm sure you appreciate the distinction between amature and professional.
and, the money you've invested so far only goes to training. very rarely
does *anyone* read a book, learn the rules, and then employ that knowledge
skillfully enough to be considered art. that comes with time and experience.
further, hacking away at something only gives you a pile of shit in the end.
;^)

| I wasn't asking anyone to write anything from scratch...just tell me
| what part(s) I need to explore.

the whole thing! what i mean to say is that it is more important that you
learn how to debug rather than asking for help whenever you get stuck. start with:
<pre>
<?= print_r($_REQUEST['sel_cols']) ?>
</pre>

| BTW, I am an airline pilot (a subject I could be considered an
| "expert") and have been called by numerous friends and acquaintances
| asking for my opinion on things for personal *and* professional
| reasons. I have never asked for anyone's paycheck for trying to be
| helpful.

i'm airforce f-18 primary - retired...and the only thing experts know is
that there is always too much to know and too little time to learn it all.
you're english is a bit confusing here. your friends/acquaintances ask your
opinion on things? like piloting an aircraft...or programming in php. as for
the paycheck...were we mechanics and you asked me to find out why your
engine - that you threw together from parts out of a scrap yard - wouldn't
turn over, unless i was getting a good reach-around, i'd just be getting
****ed by not charging...that is since i inferred you *would* be getting
paid since you are "under-the-gun" and all.
  Reply With Quote
6 12th June 14:06
robert
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


| Fatal error: Cannot instantiate non-existent class: mdb in
| /generate_report.php on line 7

add an include/require statement to the mdb class script:

require_once "/classes/mdb.class.php";

and that will take care of it...the above path and file name are wholly
incorrect, which i'm sure you understand.
  Reply With Quote
7 12th June 14:06
ward
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


OK, obviously (yes, very obvious) I'm missing something here.

It appears as though I'm missing some components here such as
mdb.class.php. Is this from the PEAR???

The only other thing I see that I'm not that familar with is
db_dbArray. I can't find much when googled.

So perhaps I should start from scratch in hopes of solving this thing
without PEAR. Though from what I'm reading, using the PEAR is suppose
to make things "easier." I'm not sure if PEAR is installed on the
hosting company's server; I am trying to find out.

So...

If I'm not mistaken, the following portion of my script creates two
arrays: sel_groups and sel_cols.

Is this a true statement?

echo '<fieldset><legend>Generate Report</legend>

<form action="generate_report.php" method="post">

<CENTER>
<TABLE BORDER="1" cellpadding="5" cellspacing="5">
<TR>
<TD rowspan="2" valign="bottom"><strong>Select
Group(s)</strong></TD>
<TD colspan="2"><strong>Select Columns</strong></TD>
</TR>
<TR>
<TD><strong>ICAO Work Programme</strong></TD><TD><strong>SME
Input</strong></TD>
</TR>
<TR>
<TD align="left" valign="top">';

require_once ('includes/mysql_connect.php'); // Connect to the
db.
$query = "SELECT * FROM groups ORDER BY groups_id ASC";
$result = @mysql_query ($query);

while($rows = mysql_fetch_array($result))
{
$id = $rows['groups_id'] ;
$name = $rows['groups_name'];

echo "<input name=\"sel_groups[]\" type=\"checkbox\"
value=\"$id\">$name<BR>\n";
}

echo '
</TD>
<TD align="left" valign="top">
<input name="sel_cols[]" type="checkbox" value="groups_name">
Group Name<BR>
<input name="sel_cols[]" type="checkbox" value="task_desc">
Description of Task<BR>
<input name="sel_cols[]" type="checkbox" value="task_id"> Task
No.<BR>
<input name="sel_cols[]" type="checkbox"
value="task_compdate">Estimated Completion Date<BR>
<input name="sel_cols[]" type="checkbox"
value="task_source">Source &amp; References<BR>
<input name="sel_cols[]" type="checkbox"
value="task_icaonote">Note on Progress<BR>
</TD>
<TD align="left" valign="top">
<input name="sel_cols[]" type="checkbox"
value="task_usposition">U.S. Position<BR>
<input name="sel_cols[]" type="checkbox"
value="task_exp_outcome">Expected Outcome<BR>
<input name="sel_cols[]" type="checkbox"
value="task_outcome">Outcome<BR>
<input name="sel_cols[]" type="checkbox"
value="task_usaction">U.S. Action<BR>
<input name="sel_cols[]" type="checkbox"
value="task_probs_issues">Problems &amp; Issues<BR>
<input name="sel_cols[]" type="checkbox"
value="task_smecomments">Notes/Comments<BR>
</TD>


</TR>

</TABLE></CENTER>

<input name="submit" type="submit" value="Generate">

</form>


Ward
  Reply With Quote
8 12th June 14:06
robert
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


| It appears as though I'm missing some components here such as
| mdb.class.php. Is this from the PEAR???

again, mdb.class.php is a ficticious name...i don't know what modules you
have or what are required...i'm not at all a fan of pear.


| The only other thing I see that I'm not that familar with is
| db_dbArray. I can't find much when googled.

i'll post a db class you can use...it will work out of the box with mysql
(that is what you have, correct?) as long as you are using php 5...if not,
well...


| So perhaps I should start from scratch in hopes of solving this thing
| without PEAR. Though from what I'm reading, using the PEAR is suppose
| to make things "easier." I'm not sure if PEAR is installed on the
| hosting company's server; I am trying to find out.

well, what it is supposed to do and what it actually does are two different
tales altogether...and yes, it is a pain in the ass when your isp doesn't
have it installed nor wants it installed.

| If I'm not mistaken, the following portion of my script creates two
| arrays: sel_groups and sel_cols.
|
| Is this a true statement?

it appears so...though i configure mine a bit differently:

<input name="sel_groups[<?= $id ?>]" type="checkbox" />

and

<input name="sel_cols[<?= $name ?>]" type="checkbox" />


==== free-bee

useage:

<?
require_once 'db.class.php';

db::connect('localhost', 'user', 'password', 'sampleDb');

$sql = "
SELECT Foo
FROM bar
WHERE 1 = 1
";
$records = db::execute($sql);
foreach ($records as $record)
{
echo '<pre>' . $record['FOO'] . '</pre>';
}
?>

==== db.class.php

<?
class db
{
static private $_instance = null;
static private $_lastStatement = '';

private function __clone(){}

private function __construct(){}

static function connect($server, $user, $password, $catalog = null)
{
try
{
mysql_connect($server, $user, $password);
if (!is_null($catalog)){ mysql_select_db($catalog); }
} catch (exception $ex) {
print "<pre>\r\n" . $ex->getMessage() . "\r\n" .
' in file ' . $ex->getFile() . "\r\n" .
' on line ' . $ex->getLine() . "\r\n" .
'</pre>';
return false;
}
return true;
}

static function getInstance()
{
if (is_null(self::$_instance)){ self::$_instance = new db(); }
return self::$_instance;
}

static function getLastStatement(){ return self::$_lastStatement; }

static function decode($string)
{
$translation = get_html_translation_table(HTML_ENTITIES);
$translation = array_flip($translation);
$string = strtr($string, $translation);
return $string;
}

static function encode($string)
{
$translation = get_html_translation_table(HTML_ENTITIES);
$string = strtr($string, $translation);
return $string;
}

static function execute($sql, $decode = false, $returnNewId = false)
{
self::$_lastStatement = $sql;
$array = array();
$key = 0;
$records = mysql_query($sql);
$fieldCount = @mysql_num_fields($records);
$translation = get_html_translation_table(HTML_ENTITIES);
$translation = array_flip($translation);
while ($row = @mysql_fetch_array($records, MYSQL_NUM))
{
for ($i = 0; $i < $fieldCount; $i++)
{
$value = $row[$i];
if ($decode){ $value = strtr($value, $translation); }
$array[$key][strtoupper(@mysql_field_name($records, $i))] = $value;
}
$key++;
}
if ($returnNewId)
{
$array = array();
$array[0]['ID'] = mysql_insert_id();
}
@mysql_free_result($records);
return $array;
}

static function prepare($string, $encode = false)
{
if ($encode){ $string = self::encode($string); }
$string = stripslashes(str_replace("'", "''", $string));
return $string;
}
}
?>
  Reply With Quote
9 12th June 14:06
ward
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


Good morning Robert.

Well guess what, apparently the hosting company does have PEAR
installed and now I'll have to figure out how to use it.

I guess what gets me is (and it's a silly rhetorical question), why is
this so complicated? In my mind's eye, I see choosing the group_id(s)
and what fields I want displayed.

Then it's a matter of extracting the data within the array and running
the query. Then of course presenting the data.

I have some more research to do.

Thanks again for the assist.

Ward
  Reply With Quote
10 12th June 14:06
robert
External User
 
Posts: 1
Default Just not getting it--need help with Generate Report function


you'll get it, i'm sure...good luck.


|
| Well guess what, apparently the hosting company does have PEAR
| installed and now I'll have to figure out how to use it.
|
| I guess what gets me is (and it's a silly rhetorical question), why is
| this so complicated? In my mind's eye, I see choosing the group_id(s)
| and what fields I want displayed.
|
| Then it's a matter of extracting the data within the array and running
| the query. Then of course presenting the data.
|
| I have some more research to do.
|
| Thanks again for the assist.
|
| Ward
|
| On Wed, 10 May 2006 17:58:31 -0500, "robert"
| <ab@no.spam-alama-ding-dong> wrote: |
| >| It appears as though I'm missing some components here such as
| >| mdb.class.php. Is this from the PEAR???
| >
| >again, mdb.class.php is a ficticious name...i don't know what modules you
| >have or what are required...i'm not at all a fan of pear.
| >
| >
| >| The only other thing I see that I'm not that familar with is
| >| db_dbArray. I can't find much when googled.
| >
| >i'll post a db class you can use...it will work out of the box with mysql
| >(that is what you have, correct?) as long as you are using php 5...if not,
| >well...
| >
| >
| >| So perhaps I should start from scratch in hopes of solving this thing
| >| without PEAR. Though from what I'm reading, using the PEAR is suppose
| >| to make things "easier." I'm not sure if PEAR is installed on the
| >| hosting company's server; I am trying to find out.
| >
| >well, what it is supposed to do and what it actually does are two different
| >tales altogether...and yes, it is a pain in the ass when your isp doesn't
| >have it installed nor wants it installed.
| >
| >
| >
| >| If I'm not mistaken, the following portion of my script creates two
| >| arrays: sel_groups and sel_cols.
| >|
| >| Is this a true statement?
| >
| >it appears so...though i configure mine a bit differently:
| >
| ><input name="sel_groups[<?= $id ?>]" type="checkbox" />
| >
| >and
| >
| ><input name="sel_cols[<?= $name ?>]" type="checkbox" />
| >
| >
| >
| >
| >==== free-bee
| >
| >useage:
| >
| ><?
| >require_once 'db.class.php';
| >
| >db::connect('localhost', 'user', 'password', 'sampleDb');
| >
| >$sql = "
| > SELECT Foo
| > FROM bar
| > WHERE 1 = 1
| > ";
| >$records = db::execute($sql);
| >foreach ($records as $record)
| >{
| > echo '<pre>' . $record['FOO'] . '</pre>';
| >}
| >?>
| >
| >==== db.class.php
| >
| ><?
| >class db
| >{
| > static private $_instance = null;
| > static private $_lastStatement = '';
| >
| > private function __clone(){}
| >
| > private function __construct(){}
| >
| > static function connect($server, $user, $password, $catalog = null)
| > {
| > try
| > {
| > mysql_connect($server, $user, $password);
| > if (!is_null($catalog)){ mysql_select_db($catalog); }
| > } catch (exception $ex) {
| > print "<pre>\r\n" . $ex->getMessage() . "\r\n" .
| > ' in file ' . $ex->getFile() . "\r\n" .
| > ' on line ' . $ex->getLine() . "\r\n" .
| > '</pre>';
| > return false;
| > }
| > return true;
| > }
| >
| > static function getInstance()
| > {
| > if (is_null(self::$_instance)){ self::$_instance = new db(); }
| > return self::$_instance;
| > }
| >
| > static function getLastStatement(){ return self::$_lastStatement; }
| >
| > static function decode($string)
| > {
| > $translation = get_html_translation_table(HTML_ENTITIES);
| > $translation = array_flip($translation);
| > $string = strtr($string, $translation);
| > return $string;
| > }
| >
| > static function encode($string)
| > {
| > $translation = get_html_translation_table(HTML_ENTITIES);
| > $string = strtr($string, $translation);
| > return $string;
| > }
| >
| > static function execute($sql, $decode = false, $returnNewId = false)
| > {
| > self::$_lastStatement = $sql;
| > $array = array();
| > $key = 0;
| > $records = mysql_query($sql);
| > $fieldCount = @mysql_num_fields($records);
| > $translation = get_html_translation_table(HTML_ENTITIES);
| > $translation = array_flip($translation);
| > while ($row = @mysql_fetch_array($records, MYSQL_NUM))
| > {
| > for ($i = 0; $i < $fieldCount; $i++)
| > {
| > $value = $row[$i];
| > if ($decode){ $value = strtr($value, $translation); }
| > $array[$key][strtoupper(@mysql_field_name($records, $i))] = $value;
| > }
| > $key++;
| > }
| > if ($returnNewId)
| > {
| > $array = array();
| > $array[0]['ID'] = mysql_insert_id();
| > }
| > @mysql_free_result($records);
| > return $array;
| > }
| >
| > static function prepare($string, $encode = false)
| > {
| > if ($encode){ $string = self::encode($string); }
| > $string = stripslashes(str_replace("'", "''", $string));
| > return $string;
| > }
| >}
| >?>
| >
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666