Jump to content


Photo

Searching through user input


  • Please log in to reply
1 reply to this topic

#1 phpnb

phpnb
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 October 2006 - 02:07 AM

hi everyone, am new here, new to php as well

have a question as i am baffled. i have been on this for a while but still searching for an answer.

heres the logic

im getting user input through a text box and storing it in a variable
im searching through a text file for a match and displaying the output. The text file holds data about cars. if the user enters lets say model then it should display the make, model, price, year, viewed values. i have got it to store the values in array form.

<html>
<head>
<title> Maximum Price  </title>
</head>

<BODY bgcolor=white vlink=white>

<FORM NAME=myForm METHOD="POST" >
Maximum Price <INPUT SIZE =12 TYPE="text" name="Numb1">
<INPUT TYPE="SUBMIT" VALUE="Process">
<p>

<?

$filename = "cars.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
fclose ($fd);
$splitcontents = explode(",", $contents);

#The following part stores make, model, price, year, viewed in array form, eg table[0], table[1]
#table[0] holds 1 record, table[1] holds another record and so on
##############
$check=0;
$nc=9;
for ($count=5; $count<count($splitcontents); $count++) {
        $table[$check][]=$splitcontents[$count];
        if ($count==$nc){
        $nc+=5;
        $check+=1;
        }
}

##############################################

$val = $_POST['Numb1'];


## as an example i was trying to display value from table[0] only but even that didnt work
for ($count=0; $count<count($table[0]); $count++){
        if($val==$table[0][$count]){                                  #if the value returned matches with
                for ($nc=0; $nc<count($table[0]); $nc++){      #any value from table[0] then print out the
                print $table[0][$nc];                                      #the whole table
                }
        }
}
###########

really need help guys
will wait for positive replies.
thanks all


#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 16 October 2006 - 02:59 AM

If I was debugging that, I would add var_dump($table) inside the loop where you create $table.  That will show you what is happening.  If that doesn't help, add var_dump($table[0]) before you try to print out $table[0].  The results should help you solve your problem :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users