resago Posted January 20, 2008 Share Posted January 20, 2008 MAN I'M TIRED, that was totaly the wrong place to put it! HAHAHAHA cut the added line: $x=0; put it here $fields = explode($sep, $lines[$y]); Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444088 Share on other sites More sharing options...
fadedline Posted January 20, 2008 Author Share Posted January 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444096 Share on other sites More sharing options...
resago Posted January 20, 2008 Share Posted January 20, 2008 I can be reached at my site in my sig Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444099 Share on other sites More sharing options...
fadedline Posted January 20, 2008 Author Share Posted January 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444167 Share on other sites More sharing options...
Barand Posted January 20, 2008 Share Posted January 20, 2008 EDIT: Completely disregard this post - I hadn't even noticed there was still another page of replies to read when I posted. Need more caffeine. //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>"; } } $y++; echo "</TR>"; } //close the table. echo "</table>"; the opening line while($y<$numlines){ has no closing "}" or is it the while($x<$numheaders){ either way, there's a mis-match Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444198 Share on other sites More sharing options...
fadedline Posted January 20, 2008 Author Share Posted January 20, 2008 Can I just add an else statement somewhere so I can redirect people if they put in wrong number? Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444369 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 at beginning add $results=0; then modify to if ($fields[0]=="$id")&&($fields[2]=="$zip"){ $results++; at the end, add if ($results==0){ print "No results"; } Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444756 Share on other sites More sharing options...
fadedline Posted January 21, 2008 Author Share Posted January 21, 2008 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444777 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 yep Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444780 Share on other sites More sharing options...
fadedline Posted January 21, 2008 Author Share Posted January 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444782 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 if (($fields[0]=="$id")&&($fields[2]=="$zipcode")){ Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444788 Share on other sites More sharing options...
fadedline Posted January 21, 2008 Author Share Posted January 21, 2008 OK it works but now I keep getting just a blank table with No Results printed. Im entering a valid id and zip code. Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444795 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 $zip Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444799 Share on other sites More sharing options...
fadedline Posted January 21, 2008 Author Share Posted January 21, 2008 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444803 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 try: if (($fields[0]=="$id")&&(trim($fields[2])=="$zip")){ Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-444806 Share on other sites More sharing options...
fadedline Posted January 21, 2008 Author Share Posted January 21, 2008 Hmmm..same result. Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-445142 Share on other sites More sharing options...
resago Posted January 21, 2008 Share Posted January 21, 2008 put print "($fields[2]) ($zip)<br>"; above the zip run it and see if they are comparable. Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-445205 Share on other sites More sharing options...
fadedline Posted January 21, 2008 Author Share Posted January 21, 2008 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-445651 Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 no. put it here so you can see what we are trying to compare. $fields = explode($sep, $lines[$y]); print "($fields[2]) ($zip)<br>"; if (($fields[0]=="$id")&&(trim($fields[2])=="$zip")){ $results++; and post your code inside of code tags. Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-445767 Share on other sites More sharing options...
fadedline Posted January 22, 2008 Author Share Posted January 22, 2008 Darn my bad, sorry been really busy today. Well it now lists all the id numbers and zip codes inside of () Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-445771 Share on other sites More sharing options...
fadedline Posted January 22, 2008 Author Share Posted January 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-445805 Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 mark as solved. Quote Link to comment https://forums.phpfreaks.com/topic/86716-solved-view-just-certian-rows-in-csv-file-after-user-inputs-id-from-a-form/page/2/#findComment-446173 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.