Current location: Hot Scripts Forums » Programming Languages » PHP » Pull specific data from flat file and display


Pull specific data from flat file and display

Reply
  #1 (permalink)  
Old 04-24-07, 09:21 PM
Andy128 Andy128 is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Pull specific data from flat file and display

I have a flat file with only a few hundred entries- nothing too complicated.
I want to pull entries that start with a specific category and display them in a table. I have the display part down. It is the pulling specific data which is the problem. So here is the first part of opening the file and breaking it up into lines of data. Now I wish to display all that have a specific "category" name.

PHP Code:

<?php

$openedfile 
fopen"listings.txt"'r' );
if(
$openedfile)
{
while (!
feof$openedfile ) )
    {
        
$line trim(fgets$openedfile ));
        if ( !empty( 
$line ) )
        {
            list(
$category$bizname$bizaddress$bizphone$line1$line2$comment) = explode"|"$line );
So can some one point me in the right direction as to what functions to use to accomplish this task

Andy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-24-07, 09:26 PM
tomasgtz tomasgtz is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

just put under last line

PHP Code:

if($category == 'specific_category')
{
   echo 
"all you need to display";

__________________
Best regards,
See the best CMS http://www.publicante.com

Tomas Gutierrez

Last edited by Christian; 04-25-07 at 07:37 PM. Reason: Please use [PHP] tags when posting PHP code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-24-07, 09:33 PM
Andy128 Andy128 is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks- but where would I put it in relation to this code:
PHP Code:

<?php

if(!file_exists("listings.txt"))
{
echo
"<center><b>List your Bussiness or Service here!!.</center></b><br/>
<center>Get your self a web presence and free advertizing.</center></br></br>"
;
exit;
}
?>
<!------IF the file DOES exist- continue on------>
<!------Now process the info in the file--------->
<?php
$openedfile 
fopen"listings.txt"'r' );
if(
$openedfile)
{
while (!
feof$openedfile ) )
    {
        
$line trim(fgets$openedfile ));
        if ( !empty( 
$line ) )
        {
            list(
$category$bizname$bizaddress$bizphone$line1$line2$comment) = explode"|"$line );
?>
<table>
    <tr >
        <td width="380" align="center" bgcolor="#ffde5e">
        <FONT COLOR="#0000ff" size="5"</FONT><b><?=$bizname;?></b></td>
    </tr>
    <tr >
        <td width="380" align="center"><?=$bizaddress;?></td>
    </tr>
    <tr >
        <td width="380" align="center"><?=$bizphone;?></td>
    </tr>
    <tr >
        <td width="380" align="center"><?=$line1;?></td>
    </tr>
    <tr >
        <td width="380" align="center"><?=$line2;?></td>
    </tr>
    <tr >
        <td width="380" align="center"><?=$comment;?></td>
    </tr>
</br>
<?
}
}
    
fclose$openedfile );
}
else
{
?>
    <tr>
        <td width="380" align"center">Cannot open file!</td>
    </tr>
<?
}
?>
</table>
Sorry for not totally understanding this.

Andy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
writing form data to a text file topside Script Requests 2 03-02-07 03:28 AM
flat file capability daleylay PHP 9 10-05-06 05:24 AM
retreived data and display data upon choice from first page? benq PHP 0 05-06-06 06:45 AM
pull code from a file nassau PHP 4 10-03-04 11:18 PM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 05:28 PM


All times are GMT -5. The time now is 09:06 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.