Click to See Complete Forum and Search --> : [RESOLVED] Advice on PHP - MySQL code


spiritssight
01-04-2008, 12:21 AM
Hello all,

I am wondering is there a better way of doing this code? what this code is doing is pulling data from a db and putting the information into the form for editing, the from will process in a different from as there is three buttons to choice from, one to accept the data, two to table for the time (to skip) three to reject (put the info into a blacklist without any changes)

only I and a couple of people will have access to the form, so right now I not worried about injection stuff, once I got things all the way I want then I will add that stuff.

Now there has to be a better way of coding this page. Thanks ahead of time!

Sincerely,
Christopher


<?php

include '/home/dev/www/includes/db_config_cr-dev.php';
include '/home/dev/www/includes/db_conn-select.php';

$query = "
SELECT *
FROM irs_eoml_rawdata
WHERE
EIN LIKE '050503820'
";

$result = mysql_query($query) OR die("Was unable to get the results!" . mysql_error());
$rows = mysql_numrows($result) OR die("Was unable to get number of rows" . mysql_error());

$i=0;
while ($i < $rows) {

$ein = mysql_result($result,$i,"EIN");
$pno = mysql_result($result,$i,"PNO");
$icn = mysql_result($result,$i,"ICN");
$sa = mysql_result($result,$i,"Street_Address");
$city = mysql_result($result,$i,"City");
$state = mysql_result($result,$i,"STATE");
$pc = mysql_result($result,$i,"Postal_Code");
$gen = mysql_result($result,$i,"GEN");
$subsection = mysql_result($result,$i,"Subsection_Code");
$affiliation = mysql_result($result,$i,"Affiliation_Code");
$classification = mysql_result($result,$i,"Classification_Code");
$rd = mysql_result ($result, $i, "Ruling_Date");
$dc = mysql_result ($result, $i, "Deductibility_Code");
$fc = mysql_result ($result, $i, "Foundation_Code");
$ac = mysql_result ($result, $i, "Activity_Code");
$oc = mysql_result ($result, $i, "Organization_Code");
$ulc = mysql_result ($result, $i, "UL_Code");
$afed = mysql_result ($result, $i, "AFED");
$tp = mysql_result ($result, $i, "Tax_Period");
$asset_c = mysql_result ($result, $i, "Asset_Code");
$income_c = mysql_result ($result, $i, "Income_Code");
$frc = mysql_result ($result, $i, "FR_Code");
$b = mysql_result ($result, $i, "Blanks");
$ap = mysql_result ($result, $i, "Accounting_Period");
$asset_a = mysql_result ($result, $i, "Asset_Amount");
$income_a = mysql_result ($result, $i, "Income_Amount");
$ian_ns = mysql_result ($result, $i, "IIANCNS_1");
$f990_ra = mysql_result ($result, $i, "F_990_RA");
$ran_ns = mysql_result ($result, $i, "IIANCNS_2");
$ntee = mysql_result ($result, $i, "NTEE_Code");
$sn = mysql_result ($result, $i, "SN_SNL");

echo '
<form name="irs_eoml" method="post" action="process.php">
<label for="ein">Employer Identification Number:</label>
<input type="text" value="'. $ein .'" id="ein" name="ein" /><br />
<label for="pno">Primary Name Organization:</label>
<input type="text" value="'. $pno .'" id="pno" name="pno" /><br />
<label for="icn">In Care of:</label>
<input type="text" value="'. $icn .'" id="icn" name="icn" /><br />
<label for="sa">Street Address:</label>
<input type="text" value="'. $sa .'" id="sa" name="sa" /><br />
<label for="city">City:</label>
<input type="text" value="'. $city .'" id="city" name="city" /><br />
<label for="state">State:</label>
<input type="text" value="'. $state .'" id="state" name="state" /><br />
<label for="pc">Postal Code:</label>
<input type="text" value="'. $pc .'" id="pc" name="pc" /><br />
<label for="gen">Group Exception Number:</label>
<input type="text" value="'. $gen .'" id="gen" name="gen" /><br />
<label for="subsection">Subsection Code:</label>
<input type="text" value="'. $subsection .'" id="subsection" name="subsection" /><br />
<label for="affiliation">Affiliation Code:</label>
<input type="text" value="'. $affiliation .'" id="affiliation" name="affiliation" /><br />
<label for="classification">Classification Codes:</label>
<input type="text" value="'. $classification .'" id="classification" name="classification" /><br />
<label for="rd">Ruling Date:</label>
<input type="text" value="'. $rd .'" id="rd" name="rd" /><br />
<label for="dc">Deductibility Code:</label>
<input type="text" value="'. $dc .'" id="dc" name="dc" /><br />
<label for="fc">Foundation Code:</label>
<input type="text" value="'. $fc .'" id="fc" name="fc" /><br />
<label for="ac">Activity Code:</label>
<input type="text" value="'. $ac .'" id="ac" name="ac" /><br />
<label for="oc">Organization Code:</label>
<input type="text" value="'. $oc .'" id="oc" name="oc" /><br />
<label for="ulc">Universal Location Code:</label>
<input type="text" value="'. $ulc .'" id="ulc" name="ulc" /><br />
<label for="afed">Advance Ruling Expiration Date:</label>
<input type="text" value="'. $afed .'" id="afed" name="afed" /><br />
<label for="tp">Tax Period:</label>
<input type="text" value="'. $tp .'" id="tp" name="tp" /><br />
<label for="asset_c">Asset Code:</label>
<input type="text" value="'. $asset_c .'" id="asset_c" name="asset_c" /><br />
<label for="income_c">Income Code:</label>
<input type="text" value="'. $income_c .'" id="income_c" name="income_c" /><br />
<label for="frc">Filing Requirement Code:</label>
<input type="text" value="'. $frc .'" id="frc" name="frc" /><br />
<label for="b">Blank Field:</label>
<input type="text" value="'. $b .'" id="b" name="b" /><br />
<label for="ap">Accounting Period:</label>
<input type="text" value="'. $ap .'" id="ap" name="ap" /><br />
<label for="asset_a">Asset Amount:</label>
<input type="text" value="'. $asset_a .'" id="asset_a" name="asset_a" /><br />
<label for="income_a">Income Amount:</label>
<input type="text" value="'. $income_a .'" id="income_a" name="income_a" /><br />
<label for="ian_ns">If Income Amount Neg: (put -)</label>
<input type="text" value="'. $ian_ns .'" id="ian_ns" name="ian_ns" /><br />
<label for="f990_ra">Form 990 Revenue Amount:</label>
<input type="text" value="'. $f990_ra .'" id="f990_ra" name="f990_ra" /><br />
<label for="ran_ns">If Revenue Amount Neg: (put -)</label>
<input type="text" value="'. $ran_ns .'" id="ran_ns" name="ran_ns" /><br />
<label for="ntee">National Taxonomy of Exempt Entities (NTEE) Code:</label>
<input type="text" value="'. $ntee .'" id="ntee" name="ntee" /><br />
<label for="sn">Sort Name Line (Secondary Name Line), if present:</label>
<input type="text" value="'. $sn .'" id="sn" name="sn" /><br />

<input type="submit" value="accept" name="Accept">
<input type="submit" value="table" name="Table">
<input type="submit" value="reject" name="Reject">
</form>
';

$i++;
}

mysql_close($conn);

?>

Weedpacket
01-04-2008, 02:47 AM
$ein = mysql_result($result,$i,"EIN");
$pno = mysql_result($result,$i,"PNO");
$icn = mysql_result($result,$i,"ICN");
$sa = mysql_result($result,$i,"Street_Address"); // etc. etc. etc.Look up mysql_fetch_array.


$i=0;
while ($i < $rows) { Consider using a for loop instead.

<label for="ein">Employer Identification Number:</label>
<input type="text" value="'. $ein .'" id="ein" name="ein" /><br /> Also begging to be replaced by a loop and an array: doing the same thing over and over again is the computer's job. Not yours.


$display_fields = array(
'EIN' => array('ein', 'Employer Identification Number:'),
'PNO' => array('pno', 'Primary Name Organization:'),
'ICN' => array('icn', 'In Care of:'),
'Street_Address' => array('sa', 'Street Address:'),
//....etc....
);


for($i=0; $i<$rows; $i++) {
$record = mysql_fetch_array($result);

echo '<form name="irs_oeml" method="post" action="process.php">';
foreach($display_fields as $dbcolumn=>$html)
{
list($formfield, $labeltext) = $html;
echo '<label for="'.$formfield.'">'.$labeltext.'</label>';
echo '<input type="text" value="'.$record[$dbcolumn].'" id="'.$formfield.'" name="'.$formfield.'" /><br />';
}
echo '</form>';
}

spiritssight
01-04-2008, 11:46 AM
I am trying to understand this:

$display_fields = array(
'EIN' => array('ein', 'Employer Identification Number:'),
);


I know that $display_fields is the var that holds the array
now what I think is happening next is that the colum name of EIN is being changed to ein and also adding a second secation to the arrray to say also this is what we want to use for form desciption, do I understand this right?


for($i=0; $i<$rows; $i++) {


this is saying if $i lessthen the rows still loop till $i = $rows if not add one to the $i


$record = mysql_fetch_array($result);


this takes the var $record and makes it into a array from the $results of the query



foreach($display_fields as $dbcolumn=>$html)
{
list($formfield, $labeltext) = $html;
}


Now this area I am confused about, I am not sure what its doing, I know its doing a loop of the array that was setup earler to hold the display info, but that is all I am getting, I do not understand the $display_fields as $dbcolumn=>$html and what the list() is doing could you explain please?

Also why do you do a echo ' '; on each line?

Sincerely,
Christopher

spiritssight
01-04-2008, 12:27 PM
I thank you for your help, it runs great!

But now I have a few questions:

How do I format this now using CSS (no tables allowed)

How do I group the different types of information using fieldset? Say the address information would be grouped together, and the financial information and so on

Also how can I have other form fields that are not from the table that was used? The information that this form get pulled into it will be getting moved to a different table(s) depending on what button is pressed.

Once again I thank you all for help with my question and this non-profit project