Forum Moderators: coopster

Message Too Old, No Replies

linking a txt database with php script

php linking to txt database

         

crizz_king

1:18 pm on Sep 2, 2005 (gmt 0)

10+ Year Member



i've just learnt html and designed my website. Part of the website has a project where i am trying to design a simple music store that, when a visitor clicks on an appropriate page creates a list of cassette titles headed by artist name, price etc from the stock that has been entered into a database. I had a similar system i created in frontpage that used a asp page to call on the data. That worked but now my servers dont support micrsoft extentions and i no longer use frontpage in preference to using notepad and html.
I found a scrpt on the web that was supposed to work but doesnt quite. i think there must be an error in the script but i dont know enough about the language to sort it out.
I wonder can anyone spot whats going wrong?
This is the script that is inserted inside paragraph tags in a TD cell of my web page table.

<?php
$fp = fopen('male.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file.</table></body></html>'; exit;}

while (!feof($fp)) {
$line = fgets($fp, 1024); //use 2048 if very long lines
list ($SURNAME, $CHRISTIAN NAME, $TITLE, $SONGS INCLUDE, $PRICE,) = split ('\¦', $line);
echo '
<tr>
<td>'.$SURNAME.'</td>
<td>'.$CHRISTIAN NAME.'</td>
<td>'.$TITLE.'</td>
<td>'.$SONGS INCLUDE.'</td>
<td>'.$PRICE.'</td>

</tr>';
$fp++;
}

fclose($fp);

?>

it calls on a txt database (male.txt)thats seperated with tabs.Its in the same folder as the html file.
perhaps i should insert the script in its own table row?
HELP.....i'm drowning..

leatherback

12:00 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



Hi,

The script you posted assumes that the values in the file are seperated by pipe symbols (¦)

you could change this to tab, I believe it is: \t
so in the script: change:

list ($SURNAME, $CHRISTIAN NAME, $TITLE, $SONGS INCLUDE, $PRICE,) = split ('\¦', $line);

to
list ($SURNAME, $CHRISTIAN NAME, $TITLE, $SONGS INCLUDE, $PRICE,) = split ('\t', $line);

Else you can make the file pipe-separated. '

Also, it requires the file to contain 5 values in a line (The five mentioned i te script line posted a few lines above).

J.

henry0

12:34 pm on Sep 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebMasterWorld crizz_King,

Beware:
Your page should be named with the .php extension. This is so the web server knows how to handle the PHP snippet for processing.
If it does not work then you need to modify your setup (httpd.conf) to allow for php to parse .html files.
Since you might not have access to it check with your ISP.

Find:
<apachedir>/conf/httpd.conf ......
AddType application/x-httpd-php .php
from here add any extensions that will be processed by PHP
for example:
AddType application/x-httpd-php .php .html
Remember to restart Apache