hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Search within php?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Search within php?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-11-2004, 04:37 PM
vision3 vision3 is offline
Web Hosting Guru
 
Join Date: Aug 2003
Location: PA
Posts: 299

Search within php?


Hi
I have setup a script to sends information to a flat file which contains table settings too, each table information sent to the flat file are unique in the sence that all the tables will always contain different info. Another file get information from a flat file and shows it. Now i want to be able to search that flat file and show the results, the person would put a number or a name in the search field and it will take them to the table where that name or number is. I dont know if im making sence but below is the actual script, now just to let you know im new at this so please bare whith me.

Form to fill out
PHP Code:
<form action="testsend.php" method=post>

Name: <input maxlength="100" name="name" value="name" size="10">
<
br><br>
Number: <input maxlength="100" name="num"  value="number" size="10">
<
br><br>
<
input type="submit" value="Send">

</
form
testsend.php - sends info to file
PHP Code:
<?

$date 
date("H:i, jS F");
echo 
$date;
echo 
"<br>";
 if( 
$name == "name" )
  {
    echo 
"You did not enter a name. <br>Please go back and add your name!<br>";
exit;
}
if( 
$num == "number" )
  {
    echo 
"You did not enter a number. <br>Please go back and add your numb er!<br>";
exit;
  }  
  else
  {
  
$outputstring "<tr><td bgcolor=\"silver\">\t" .$date"</td></tr><tr><td>Full Name: \t".$name"</td></tr><tr><td bgcolor=\"silver\">DOMAIN: \t".$num"</td></tr>\n";

$fp fopen("test.txt""a");

  
flock($fp2); 
 
  
fwrite($fp$outputstring);
  
flock($fp3); 
  
fclose($fp);

  echo 
"<p>Results: <b>Information was sent</b>.</p>";

}
?>
testview.php - where i can view my flat file info
PHP Code:
<?
if (file_exists("test.txt"))
    echo 
"test file output:";
else
    echo 
"no info inside.";
    
$fp fopen("test.txt""r");
    if (!
$fp)
    {
        echo 
"<td><p><strong>No info here."
              
."Please try again later.</strong></p></td></table></body></html>";
              exit;
     }
     
     while (!
feof($fp))
     {
         
$orderfgets($fp100);
        echo 
$order;


        
      }
      echo 
"Filesize: ";
      echo 
filesize("test.txt");
      echo 
"bytes";
flock($fp1);
flock($fp3);
      
fclose($fp);

?>
any advice is welcome

Reply With Quote


Sponsored Links
  #2  
Old 01-13-2004, 07:49 PM
Rahde Rahde is offline
WHT Addict
 
Join Date: Oct 2003
Posts: 115
one piece of advice I would offer is not to use global variables.

use $_POST['name'] instead of $name;

Reply With Quote
  #3  
Old 01-13-2004, 09:30 PM
vision3 vision3 is offline
Web Hosting Guru
 
Join Date: Aug 2003
Location: PA
Posts: 299
thanks ill make thst change

Reply With Quote
Sponsored Links
  #4  
Old 01-14-2004, 12:07 AM
XYPHEN XYPHEN is offline
Disabled
 
Join Date: Nov 2002
Location: ON, Canada
Posts: 288
I don't get this, can you explain a bit more??

Regards,
Ali

Reply With Quote
  #5  
Old 01-14-2004, 10:41 AM
vision3 vision3 is offline
Web Hosting Guru
 
Join Date: Aug 2003
Location: PA
Posts: 299
Well let me see. I have this setup so that only a name and number is enter into the flat file. I want to be able to search that file by using either the persons name or their number. Once it has found the name or the number it will show it but both info, the name and the number. so that when you view it you will see something like this:
=======================
NAME: JONH DOE
NUMBER: 2035gs237y952
=======================

The file may have many more info like this but i want it to ba able to show only the an exact info. I know this is possible thru DB but i just wanted to know if its posible to search a flat file and only display a specific info.

Reply With Quote
  #6  
Old 01-14-2004, 12:37 PM
CreativeLogic CreativeLogic is offline
Web Hosting Guru
 
Join Date: Aug 2002
Posts: 261
Yea it's possible. It would be A LOT faster if you had it in a database, but to do it with a file, you need to get the file contents and store it in a variable. Then you want to use regular expressions, one of the many you can use and search for the content.

Reply With Quote
  #7  
Old 01-14-2004, 01:28 PM
vision3 vision3 is offline
Web Hosting Guru
 
Join Date: Aug 2003
Location: PA
Posts: 299
cool. is it posible for anyone to give an example to get me started. I mean im not really looking for the hole answerd but just a sample of how any one would do it.

Reply With Quote
  #8  
Old 01-22-2004, 06:19 PM
vision3 vision3 is offline
Web Hosting Guru
 
Join Date: Aug 2003
Location: PA
Posts: 299
any one?

Reply With Quote
  #9  
Old 01-23-2004, 12:18 AM
kneuf kneuf is offline
Web Hosting Master
 
Join Date: Feb 2003
Location: Canada
Posts: 716
try this:
PHP Code:
$file file('some_db.db');
foreach (
$file as $value)
{
$temp explode('::'trim($value));
$search[$temp[0]]['name'] = $temp[0];
$search[$temp[0]]['number'] = $temp[1];

its just the basic thing but might help ya, of course I assume the db would look something like:
Code:
JOHN DOE::2035gs237y952
an example call to it would be:
PHP Code:
/*
these don't have to be in the foreach statement
*/
$name $search['JOHN DOE']['name'];
$number $search['JOHN DOE']['number']; 
hope it helps ya get started

__________________
www.kneuf.com
Proudly Canadian

Reply With Quote
  #10  
Old 01-23-2004, 11:44 AM
vision3 vision3 is offline
Web Hosting Guru
 
Join Date: Aug 2003
Location: PA
Posts: 299
hmm ill try that out. Thanks alot

Reply With Quote
  #11  
Old 01-24-2004, 12:19 AM
pharmatic pharmatic is offline
Disabled
 
Join Date: Jan 2004
Posts: 3
yeah true, that would be the best way

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Why You Should Embrace Google Plus Blog 2013-03-08 09:18:17
Internet Organization ICANN Compiles Longlist of CEO/President Candidates Web Hosting News 2012-02-24 09:51:45
Google+ Business Pages – Implications for Search Marketing Blog 2012-01-25 09:58:46
ICANN Finalizes Job Description for CEO Position Web Hosting News 2011-12-22 18:43:37
ICANN Details Search for its Next CEO Web Hosting News 2011-12-13 20:36:42


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?