Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Load info in two columns from flat file


[SOLVED] Load info in two columns from flat file

Reply
  #1 (permalink)  
Old 12-08-08, 08:35 PM
Andy128 Andy128 is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Load info in two columns from flat file

I am trying to figure out how to have the script load the info from
the flat file into two columns. Can't seem to get there. Here is my
script..............any help appreciated.

PHP Code:

<?php

//Declare and assign variable
$pg_genre addslashes($_GET['pg_genre']);
//
//Now open file
if(!file_exists("listing_db.txt"))
{
echo
"<table width=350 align=center>";
echo
"<tr>";
echo
"<td class='th tc ol fw fc'>NO RECORDS AT THIS TIME</td>";
echo
"<tr>";
echo
"<td class='th tc ol fw fc'>CHECK BACK LATER</td>";
echo
"</tr>";
echo
"</table>";
exit;
}
echo
"<div style=\"border:3px #ccdd88 solid; width:350px; height:500px; overflow:auto;\">";
echo
"<table border=6 align=left width=325 cellpadding=2 cellspacing=2>";
echo
"<tr>";
echo
"<th class='th tc ol fw fc'>Welcome to DB Gallery of Fine Things</th>";
echo
"</tr>";
//
$openedfile fopen"listing_db.txt"'r' );
if(
$openedfile)
{
while (!
feof$openedfile ) )
    {
        
$line trim(fgets$openedfile ));
        if ( !empty( 
$line ) )
        {
            list( 
$genre,$entry1,$entry2$entry3$entry4,) = explode"|"$line );
//////////////////////////////////
//Now check to see which ones match the link and then post them in the table
//
if($genre == $pg_genre)
{
//Only one column with four rows
echo"<tr class=>";
echo
"<td class='td tc w2 fw ol ff'><img src=\"http://www.netisopen.com/db_images/$entry1\"></td>";
echo
"</tr>";
echo
"<tr>";
echo
"<td class='td tc w2'><a href=\"http://www.netisopen.com/db_images/$entry2\" target=\"_blank\">Click for Large View</td>";
echo
"</tr>";
echo
"<tr>";
echo
"<td class='td tc w2 fw fc'>$entry3</td>";
echo
"</tr>";
echo
"<tr>";
echo
"<td class='td tc w2'>$entry4</td>";
echo
"</tr>";
//
}
}
}
echo
"</table>";
echo
"</div>";
fclose$openedfile );
}
else
{
echo
"<br /><br />FILE COULD NOT BE OPENED!";
}
?>
Cheers-
Andy
Reply With Quote
  #2 (permalink)  
Old 12-08-08, 09:54 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Explain what you mean by two columns.
__________________
Jerry Broughton
Reply With Quote
  #3 (permalink)  
Old 12-08-08, 10:06 PM
Andy128 Andy128 is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Hey Jerry-

Well, the info from the database is loaded into the table via the echo one line at a time an therefore, $entry1, $entry2, $entry3 and $entry4 are stacked one ontop of the other and then the code runs through a gain starting a new row and doing the same untill the db is at an end. This results in one column of information.

What I would like is to have two columns. Have the db info fill side by side like so

info here-----------------------------info here
2nd line info-------------------------2nd line info
3rd line info--------------------------3rd line info

**minus the ---- as that is the only way I can display the spaces here

The table would continue until the db info was exhausted.

Does that make sense? As the code stands now it looks like this

info here
2nd line info
3rd line info

infor here
2nd line info
3rd line info

etc...........until the db query is exhasuted.

Hope that helps-
Andy

Last edited by Andy128; 12-08-08 at 10:09 PM.
Reply With Quote
  #4 (permalink)  
Old 12-08-08, 11:35 PM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Explode your file into an array and then output it like this:

PHP Code:

<?php
if(!empty($_GET['pg_genre']))
{
 
$sw=0
 
$pg_genre addslashes($_GET['pg_genre']);
 echo 
"<div style='border:3px #ccdd88 solid;width:350px;height:500px;overflow:auto;'>
        <table border='6' align='left' width='325' cellpadding='2' cellspacing='2'>
         <tr>
          <th class='th tc ol fw fc' colspan='2'>Welcome to DB Gallery of Fine Things</th>
         </tr>"
;
 if(!
file_exists("listing_db.txt"))
 {
  echo
"<tr>
        <td class='th tc ol fw fc' align='center'>NO RECORDS AT THIS TIME<br />CHECK BACK LATER</td>
       </tr>"
;
  }
 elseif(
$file = @fopen("listing_db.txt","r"))
 {
  while(!
feof($file))
  {
   if(
$line trim(fgets($file)))
   {
    
// Explode the file into arrays
    
list($genre[],$entry1[],$entry2[],$entry3[],$entry4[]) = explode("|",$line);
    }
   }
  
fclose($file);
  }
 else
 {
  echo
"<tr><td colspan='2' align='center'>FILE COULD NOT BE OPENED!</td></tr>";
  }
 if(
$genre)
 {
  
// Re-arrange the variables to sort any way you want.
  
array_multisort($genre,$entry1,$entry2,$entry3,$entry4);
  
$count=0;
  echo
"<tr>";
  for(
$i=0;$i<count($genre);$i++)
  {
   if(
$pg_genre == $genre[$i])
   {
     
$sw=1;
     echo 
"<td width='50%'><table>
            <tr>
             <td class='td tc w2 fw ol ff'><img src='http://www.netisopen.com/db_images/
$entry1[$i]' alt='$entry1[$i]'></td>
            </tr>
            <tr>
             <td class='td tc w2'><a href='http://www.netisopen.com/db_images/
$entry2[$i]' target='_blank'>Click for Large View</td>
            </tr>
            <tr>
             <td class='td tc w2 fw fc'>
$entry3[$i]</td>
            </tr>
            <tr>
             <td class='td tc w2'>
$entry4[$i]</td>
            </tr>
           </table></td>"
;
     
$count++;
    }
   if(
$count == 2)
   {
    
$count=0;
    echo 
"</tr><tr>";
    }
   }
  if(!
$sw)
  {
   echo 
"<tr><td colspan='2' align='center'>No records found.</td></tr>";
   }
  }
 if(
$count)
 {
  echo 
"<td>&nbsp;</td></tr>";
  }
 echo
"</table>";
 echo
"</div>";
 }
else
{
 echo 
"<div style='text-align:center;font-size:20px;color:#f00;background:#ffee00;width:400px;padding:10px;'>You do not have permission to access this page.</div>";
 }
?>
__________________
Jerry Broughton

Last edited by job0107; 12-08-08 at 11:54 PM.
Reply With Quote
  #5 (permalink)  
Old 12-09-08, 08:18 AM
Andy128 Andy128 is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Jerry- I'll give it a whirl.

Andy
Reply With Quote
  #6 (permalink)  
Old 12-16-08, 07:19 PM
Andy128 Andy128 is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Spin

Jerry-
Worked like a charm- Thanks a million.

Andy
Reply With Quote
  #7 (permalink)  
Old 12-19-08, 06:58 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your welcome.
__________________
Jerry Broughton
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
Hello all, can you help me? K4ot1K Other Languages 2 01-23-09 05:23 AM
flat file capability daleylay PHP 9 10-05-06 04:24 AM
The best way to save info to flat file? magicadmin PHP 1 07-09-06 11:24 AM
Heres one, mysql statement to load a table with a file from ftp?? 0o0o0 PHP 8 04-28-06 01:32 AM
Upload file to table so ONLY files tied to primary key are displayed in record? grafixDummy PHP 4 12-20-03 04:28 PM


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