Jump to content

fadedline

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fadedline's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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
  2. Darn my bad, sorry been really busy today. Well it now lists all the id numbers and zip codes inside of ()
  3. 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"; } ?>
  4. 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"; } ?>
  5. OK it works but now I keep getting just a blank table with No Results printed. Im entering a valid id and zip code.
  6. OK now I get this error - Parse error: parse error, unexpected T_BOOLEAN_AND in /home/greg/public_html/klas/account.php on line 138
  7. 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"; } ?>
  8. Can I just add an else statement somewhere so I can redirect people if they put in wrong number?
  9. 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.
  10. Perfect again!! Well I think we can call this one solved. Dude u really saved my butt...Ill post a link to the final site when its up in a few days. (you can see your work...hahaha) If you ever need design work done hit me up, I owe u. Greg
  11. Genius! It works perfect. Ok here is the line with the " " in my CSV 13248,"sims, jesse",42206, $100.00 So what its doing is using sims and jesse to fill the second and third field then its pusing the zip into the ammont field
  12. OH MAN U ARE AWESOME!!! IT WORKS Wow I cant thank you enough. The only problem I see is that the table wants to extend down very far like 1600pixels. And I just realized that any commas in " " dont work. It treats the comma like another column. Believe me Im not complaining though!!
  13. 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>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.