Jump to content

Best way to proceed, reading text


xcandiottix

Recommended Posts

I have a text file as so:

 

A

B

C

 

I want to have A,B,C available for an ajax function. With in the function I would like any change that the user makes to be reflected in the text file, so for example:

 

User changes A to 1, text file now shows:

 

1

B

C

 

I have already made the text file a .php file but now I'm stumped as to the best way to proceed. Can anyone point to any tutorials that might help me? (Already know about fopen, fwrite, etc. but i need to know how to actually piece it together rather then read function parameters)

Link to comment
Share on other sites

are the A B C values corresponding to text-boxes,

i.e. Maths = A

English = B

Science = C ?

 

and may one value be empty?

 

or is it just a textarea with "A

B

C" - i.e. the abc  data holds no correspondence

 

For sake of sanity I'll keep the convo going...

 

A

B

C

 

will be properties in a CSS file. I want a user to be able to change settings of a CSS file using ajax so the changes are live updating. But, the CSS file also must remain intact so it can be called via html when the page loads. My current plan of attack is to 'read' the css file with php and then change the CSS as changes are made by the user with php's fwrite function. So, no they do not correspond to text boxes.

Link to comment
Share on other sites

Will there only be one user?  If yes, then this solution is fine (the CSS will require a page reload before it takes place).  However, if there is more than one user, you may want to consider throwing it in a table in a database and then just echoing the contents whenever they load pages.

 

~juddster

Link to comment
Share on other sites

~juddster

 

Yes, there will be many users. I was considering the database route but I'm so concerned about database use. I've tried to put anything I can into XML or CSS files. Mostly because I don't have any php/mysql database use experience in a high user count environment. Maybe you can tell me everythings okay and just stuff that database to the max  ;D

Link to comment
Share on other sites

databases are designed to cope with high amounts of activity.

A database would be much more practical for this task, and in a db you would have specific CSS / theme values for each user, rather than a specific file for each user.

 

IMO a database is a much more practical option. It will be readily editable by future programmers who work on this project, rather than forcing them to understand your stores of XML data.

 

Another problem with storing the data in text files is the greater possibility of bugs in your code - reading and writing to these files, delimiters, server strain, etc.

Link to comment
Share on other sites

Another problem with storing the data in text files is the greater possibility of bugs in your code - reading and writing to these files, delimiters, server strain, etc.

 

Excellent points. Now, my only question is that the CSS style sheet is rather lengthy.. around 600-ish lines. I'm going to try and slim this down but will having 600 columns per user be a major slow down? I was thinking yes so I was going to provide each user with a CSS file and go from there.

Link to comment
Share on other sites

Why would you have having 600 columns per user?  Just make a text field in and you should be good to go ...

 

CREATE TABLE user_styles
(
    user_id UNSIGNED INT PRIMARY KEY NOT NULL,
    style TEXT NOT NULL
)

 

Something along those lines where user_id would actually be a foreign key to a users table of some sort.

 

~juddster

Link to comment
Share on other sites

Why would you have having 600 columns per user?  Just make a text field in and you should be good to go ...

 

CREATE TABLE user_styles
(
    user_id UNSIGNED INT PRIMARY KEY NOT NULL,
    style TEXT NOT NULL
)

 

Something along those lines where user_id would actually be a foreign key to a users table of some sort.

 

~juddster

 

I'm affraid I don't quite understand what you mean. Let me try to explain what's going on on my end better.

 

User logs into their user page. User page contains elements including a table, a banner, a table, & a table with 3 cells.

 

<table>

    <banner></banner>

    <table></table>

    <table>

              <cell></cell>

              <cell></cell>

              <cell></cell>

    </table>

</table>

 

Now, each element has its own CSS rule in the CSS file except for banner.

 

CSS File:

.table 1{

...}

.table2{

...}

.table3{

...}

.cell1{

...}

.cell2{

...}

.cell3{

...}

 

Each Rule has practically every CSS property available (approx 100 properties). So:

 

.table1{

background

border

etc..etc.. to z-index}

 

Now, if i made a table for this, say users_settings it would have to look like this:

 

$ID | background | boarder | .. .. all the rest .. .. | z-index

1            #FFF            0                                            0   

 

Which would be 600ish values across. My idea was to just give each user a .css file of thier own instead of making such a hefty database.

 

 

Link to comment
Share on other sites

I was saying let them set all of the CSS for themselves in that area.. or if you don't want it directly in the text area like that, make it so that they have individual fields for each of the classes you want and then build the css file before entering it into the database.

 

Then you will basically be able to do a query on the user, and just echo whatever they have as their CSS on the page.

 

~juddster

Link to comment
Share on other sites

Oh.... I understand, One text cell.... duh. Yeah that's a good idea but then they will save it as a blob. This is assuming each user knows CSS but i think the direction i'm supposed o be going is assuming each user does not know how to use CSS. In such a case I would have to be able to provide an option to choose from in each field. So, I think I would still be stuck either going 1 cell for each CSS property (which i've been able to slim down from 600 to 180) or doing the CSS file method. Since each user already has an XML file, I wonder if I should just put the style sheet as part of the xml. Let me lay down some code and see where this goes.

Link to comment
Share on other sites

To make it easier for them you could make a form of sorts to make the CSS file for them ... i.e.

 

Cell 1:

Font Name: >input<

Font Colour: >input<

Background Colour: >input<

 

Cell 2:

Font Name: >input<

Font Colour: >input<

Background Colour: >input<

 

Then when its posted ... you change it to:

.cell1
{
   color: $_POST [ 'cell1_colour' ];
   background-color: $_POST [ 'cell1_bg' ]; 
}

...

 

This way all they need to know is font names and colours ... not CSS.

 

Then you save that generated CSS file to the database.

 

~juddster

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.