Reply
php tables
Old 05-07-2008, 01:34 AM php tables
Super Talker

Posts: 128
my php code
PHP Code:
<?php
$fp 
fopen('data.txt','r');
if (!
$fp) {echo 'ERROR: Unable to open file.'; exit;}
 
while (!
feof($fp)) {
$line fgets($fp1024); //use 2048 if very long lines
list ($field1$field2$field3) = split ('\|'$line);
echo 
'
<div><a href="'
.$field1.'">'.$field2.'<br><img src="'.$field3.'"></a></div>';
$fp++;
}
 
fclose($fp);
 
?>
my text database code per line
Code:
URL|NAME|IMAGE
how can i get the data (more that 1 line) to show up side by side for a set number before starting a new one. (all images will be the same size, and at the moment it shows the information line after line.
(I have not used tables but i think that the tables will be the only way to go for what I want.)
simster is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Old 05-07-2008, 10:23 AM Re: php tables
addonchat's Avatar
Skilled Talker

Posts: 97
Name: Chris Duerr
Tables aren't necessary, but they're commonly used. You just need to modify your loop. For example, if you want it to show three links/images per line:
PHP Code:
$i 0;
while(!
feof($fp)) {   
   
$i++;
   
/* Do your stuff */
   
if(($i 3)==0)
   {
      
// End your table row here.
   
}

There are a couple small things this doesn't take into account, but you get the idea
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:11 PM Re: php tables
Super Talker

Posts: 128
done

new problem,

how do i get it to only show certain stuff based on whats in $field3.

for example if in
$field3 there is the text butterflye then It only shows those on that page. (On different pages I want to set it to show other pets)
simster is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:15 PM Re: php tables
Super Talker

Posts: 128
also this code isnt working (page doesnt load)

Quote:
<?php
$fp = fopen('data.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}

while (!feof($fp)) {
$line = fgets($fp, 1024); //use 2048 if very long lines
list ($field1, $field2, $field3) = split ('\|', $line);


$i = 0;
while(!feof($fp)) {
$i++;
echo '<td class="td"><div align="center"><a href="'.$field1.'">'.$field2.'<br><img src="pets/'.$field3.'.png" width="110"></a></div></td>';
if(($i % 3)==0)
{
echo "</tr>";
echo "<tr>";
}
}


$fp++;
}

fclose($fp);
?>
full code (php+html+css)
Quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">

html {min-width:800;}

img { behavior: url(iepngfix.htc) }

a img, a {border:0; padding:0; margin:0; color:#1d5a27;}
body {background-color:#b9a4c2;}

.td {border-style:solid; border-color:#b9a4c2; border-width: 20px; background-color:#82de8d;}
</style>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" style="background-color:#82de8d; "><div align="center"><img src="header.png"></div></td>
</tr>
<tr>
<td width="200" valign="top" style="padding:10px; " class="td"> nav bar </td>
<td width="600"><div align="center">
<table><tr>
<?php
$fp = fopen('data.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}

while (!feof($fp)) {
$line = fgets($fp, 1024); //use 2048 if very long lines
list ($field1, $field2, $field3) = split ('\|', $line);


$i = 0;
while(!feof($fp)) {
$i++;
echo '<td class="td"><div align="center"><a href="'.$field1.'">'.$field2.'<br><img src="pets/'.$field3.'.png" width="110"></a></div></td>';
if(($i % 3)==0)
{
echo "</tr>";
echo "<tr>";
}
}


$fp++;
}

fclose($fp);
?>
</tr></table>
</div></td>
</tr>
</table>
</body>
</html>

Last edited by simster : 05-07-2008 at 07:18 PM.
simster is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:26 PM Re: php tables
addonchat's Avatar
Skilled Talker

Posts: 97
Name: Chris Duerr
Stop incrementing $fp
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:28 PM Re: php tables
addonchat's Avatar
Skilled Talker

Posts: 97
Name: Chris Duerr
Oh -- and from your code it looks like there is only one set of data per line, so you can call fgets without the second parameter.
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:29 PM Re: php tables
Super Talker

Posts: 128
i have removed

$fp++;
}

and it still doesnt work.
simster is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:31 PM Re: php tables
addonchat's Avatar
Skilled Talker

Posts: 97
Name: Chris Duerr
What does your web server error log say? Any warnings generated? If you view the source do you just see empty table data? Throw in some print() commands to see where it's stopping.
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:31 PM Re: php tables
Super Talker

Posts: 128
there is nothing in the pages source at all.
simster is offline
Reply With Quote
View Public Profile
 
Old 05-07-2008, 07:52 PM Re: php tables
VirtuosiMedia's Avatar
Ultra Talker

Latest Blog Post:
Web Development Business Tips
Posts: 397
Are you including your html page into your php page?
VirtuosiMedia is online now
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-07-2008, 07:57 PM Re: php tables
Super Talker

Posts: 128
its one page.

a php page with html and css.
simster is offline
Reply With Quote
View Public Profile
 
Old 05-08-2008, 12:44 AM Re: php tables
nickohrn's Avatar
Weightlifting CS Student

Posts: 480
Name: Nick Ohrn
simster - could you post a sample data file?
__________________
NickOhrn.com - My personal haven of insight to offer the world.
Plugin-Developer.com - Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
nickohrn is online now
Reply With Quote
View Public Profile Visit nickohrn's homepage!
 
Old 05-08-2008, 12:48 AM Re: php tables
Super Talker

Posts: 128
I fixed this (had to rewrite code 2 times after the code I put up here)
simster is offline
Reply With Quote
View Public Profile
 
Old 05-08-2008, 12:58 AM Re: php tables
nickohrn's Avatar
Weightlifting CS Student

Posts: 480
Name: Nick Ohrn
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
html {
    min-width: 800;
}

img {
    behavior: url(iepngfix.htc)
}

a img,a {
    border: 0;
    padding: 0;
    margin: 0;
    color: #1d5a27;
}

body {
    background-color: #b9a4c2;
}

.td {
    border-style: solid;
    border-color: #b9a4c2;
    border-width: 20px;
    background-color: #82de8d;
}
</style>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td colspan="2" style="background-color: #82de8d;">
        <div align="center"><img src="header.png"></div>
        </td>
    </tr>
    <tr>
        <td width="200" valign="top" style="padding: 10px;" class="td">nav bar
        </td>
        <td width="600">
        <div align="center">
        <table>
            <?php
            $fp 
fopen('data.txt','r');
            if (!
$fp) {echo 'ERROR: Unable to open file.'; exit;}

            while (!
feof($fp)) {
                
$line fgets($fp1024); //use 2048 if very long lines
                
list (trim($field1), trim($field2), trim($field3)) = split ('\|'$line);


                echo 
"<tr>";
                echo 
'<td class="td"><div align="center"><a href="'.$field1.'">'.$field2.'<br><img src="pets/'.$field3.'.png" width="110"></a></div></td>';
                echo 
"</tr>";


                
$fp++;
            }

            
fclose($fp);
?>
        </table>
        </div>
        </td>
    </tr>
</table>
</body>
</html>
That should solve your problem if I'm understanding it correctly. Let me know.
__________________
NickOhrn.com - My personal haven of insight to offer the world.
Plugin-Developer.com - Custom plugin development to fit your needs. Plugins available for WordPress and Drupal, among others.
nickohrn is online now
Reply With Quote
View Public Profile Visit nickohrn's homepage!
 
Old 05-08-2008, 01:03 AM Re: php tables
Super Talker

Posts: 128
its all fixed and I added a kind of sort to it. (its now in pagination help?) with a different question.
simster is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to php tables
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.23374 seconds with 14 queries