fadedline
Members-
Posts
23 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
fadedline's Achievements
Newbie (1/5)
0
Reputation
-
Man thanks for showing me how to print the results....im so stupid. I realized i added one more field to the csv file and that was throwing it off!! Im sorry man I smacked myself for that one. But it does work! It matches id and zip. had to change it to if (($fields[0]=="$id")&&(trim($fields[3])=="$zip")){ Thanks again
-
Ok this is what it spits out when i do that - () () ID Number Owner Name Street City State Zip Code Amount No results Of course the Fields are in a table. Here is my html for the form- <form action="account.php" method="post"> <table width="302" height="112" border="0" align="center" cellpadding="4" cellspacing="4" bordercolor="#0092DF" bordercolorlight="#0077BB" bordercolordark="#336699" bgcolor="#CCCCCC" summary="feedback form"> <tr> <th width="96" bgcolor="#006699"><span class="style14">ID Number</span></th> <td width="168"><input name="idnumber" type="text" size="25" /></td> </tr> <tr><th bgcolor="#006699"><div align="left"> <p align="center" class="style27 style2 style4 style15">Zip Code</p> </div></th> <td><input name="zipcode" type="text" size="25" /></td> </tr> <tr> <th colspan="2"><input type="submit" value="Login" /></th> </tr> <tr></tr> </table> </form> Here is the PHP - <? $results=0; $id = $_POST['idnumber']; print "($fields[2]) ($zip)<br>"; $zip = $_POST['zipcode']; $sep = ","; $file = "accounts.csv"; //read the file into an array $lines = file($file); //count the array $numlines = count($lines); //explode the first (0) line which will be the header line $headers = explode($sep, $lines[0]); //count the number of headers $numheaders = count($headers); $i = 0; //start formatting output echo "<table border = 2 cellpadding = 6 cellspacing= 5 align=center bordercolor=#34587A><tr>"; //loop through the headers outputting them into their own <TD> cells while($i<$numheaders){ $headers = str_replace("\"", "", $headers); echo "<td bgcolor=#34587A class=style15 >".$headers[$i]."</td>"; $i++; } echo "</tr>"; $y = 1; //Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread. while($y<$numlines){ $x=0; $lines[$y]=preg_replace('/(.*)"(.+),(.+)"(.*)/', '$1$3 $2$4', $lines[$y]); $fields = explode($sep, $lines[$y]); if (($fields[0]=="$id")&&(trim($fields[2])=="$zip")){ $results++; echo "<TR>"; $fields = str_replace("\"", "", $fields); while($x<$numheaders){ echo "<TD class=style1>".$fields[$x]." </TD>"; $x++; } echo "</TR>"; } $y++; } //close the table. echo "</table>"; if ($results==0){ print "No results"; } ?>
-
OK changed it to this with same results- <? $results=0; $id = $_POST['idnumber']; $zip = $_POST['zipcode']; $sep = ","; $file = "accounts.csv"; //read the file into an array $lines = file($file); //count the array $numlines = count($lines); //explode the first (0) line which will be the header line $headers = explode($sep, $lines[0]); //count the number of headers $numheaders = count($headers); $i = 0; //start formatting output echo "<table border = 2 cellpadding = 6 cellspacing= 5 align=center bordercolor=#34587A><tr>"; //loop through the headers outputting them into their own <TD> cells while($i<$numheaders){ $headers = str_replace("\"", "", $headers); echo "<td bgcolor=#34587A class=style15 >".$headers[$i]."</td>"; $i++; } echo "</tr>"; $y = 1; //Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread. while($y<$numlines){ $x=0; $lines[$y]=preg_replace('/(.*)"(.+),(.+)"(.*)/', '$1$3 $2$4', $lines[$y]); $fields = explode($sep, $lines[$y]); if (($fields[0]=="$id")&&($fields[2]=="$zip")){ $results++; echo "<TR>"; $fields = str_replace("\"", "", $fields); while($x<$numheaders){ echo "<TD class=style1>".$fields[$x]." </TD>"; $x++; } echo "</TR>"; } $y++; } //close the table. echo "</table>"; if ($results==0){ print "No results"; } ?>
-
Like this??- <? $results=0; $id = $_POST['idnumber']; $zip =$_POST['zipcode']; $sep = ","; $file = "accounts.csv"; //read the file into an array $lines = file($file); //count the array $numlines = count($lines); //explode the first (0) line which will be the header line $headers = explode($sep, $lines[0]); //count the number of headers $numheaders = count($headers); $i = 0; //start formatting output echo "<table border = 2 cellpadding = 6 cellspacing= 5 align=center bordercolor=#34587A><tr>"; //loop through the headers outputting them into their own <TD> cells while($i<$numheaders){ $headers = str_replace("\"", "", $headers); echo "<td bgcolor=#34587A class=style15 >".$headers[$i]."</td>"; $i++; } echo "</tr>"; $y = 1; //Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread. while($y<$numlines){ $x=0; $lines[$y]=preg_replace('/(.*)"(.+),(.+)"(.*)/', '$1$3 $2$4', $lines[$y]); $fields = explode($sep, $lines[$y]); if ($fields[0]=="$id")&&($fields[2]=="$zipcode"){ $results++; echo "<TR>"; $fields = str_replace("\"", "", $fields); while($x<$numheaders){ echo "<TD class=style1>".$fields[$x]." </TD>"; $x++; } echo "</TR>"; } $y++; } //close the table. echo "</table>"; if ($results==0){ print "No results"; } ?>
-
OK sorry one last question...how do i add the zip code input from the form to match with the id? So right now I have - //Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread. while($y<$numlines){ $x=0; $lines[$y]=preg_replace('/(.*)"(.+),(.+)"(.*)/', '$1$3 $2$4', $lines[$y]); $fields = explode($sep, $lines[$y]); if ($fields[0]=="$id") { echo "<TR>"; $fields = str_replace("\"", "", $fields); while($x<$numheaders){ echo "<TD> ".$fields[$x]." </TD>"; $x++; } echo "</TR>"; } $y++; } //close the table. echo "</table>"; I know I need to add $zip to the top like this right? $zip = $_POST['zipcode']; But then where would i need to add that so both ID and Zip numbers match and go to the correct row? Its probably good to dump the user to an error page if they dont match.
-
No Problem...again thanks for all your help, u rule! Here it is - <body> <? $id = $_POST['idnumber']; $sep = ","; $file = "demoCSV.csv"; //read the file into an array $lines = file($file); //count the array $numlines = count($lines); //explode the first (0) line which will be the header line $headers = explode($sep, $lines[0]); //count the number of headers $numheaders = count($headers); $i = 0; //start formatting output echo "<table border = 1 cellpadding = 2><tr>"; //loop through the headers outputting them into their own <TD> cells while($i<$numheaders){ $headers = str_replace("\"", "", $headers); echo "<td>".$headers[$i]."</td>"; $i++; } echo "</tr>"; $y = 1; //Output the data, looping through the number of lines of data and also looping through the number of cells in each line, as this is a dynamic number the header length has to be reread. while($y<$numlines){ $x=0; echo "<TR>"; while($x<$numheaders){ $fields = explode($sep, $lines[$y]); if ($fields[0]=="$id") { $fields = str_replace("\"", "", $fields); while($x<$numheaders){ echo "<TD> ".$fields[$x]." </TD>"; $x++; } } $y++; echo "</TR>"; } //close the table. echo "</table>"; ?> </body>