Need a bit of php help...
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
I need the php that will open a .txt or .dat file thats setup like this:
3|name here
2|name here
1|name here
and seperates the first 30 lines and gives them the varibles:
$newid1 and $newname1 for the first line,
$newid2 and $newname2 for the second line ETC.
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
You won't beleive this untill its done, but i'm making a flash portal that works entirely on .dat/.txt files. NO MySQL.
60% done so far.
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
Yes, I believe it.
And because I'm in a good mood, here's the code:
<?php
$file = file('file.txt');
foreach($file as $key => $value)
{
if($key > 30)
break;
$exp = explode("|", $value);
$varname1 = "newid".$key;
$varname2 = "newname".$key;
$$varname1 = $exp[0];
$$varname2 = $exp[1];
}
?>
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/27/06 05:53 PM, elbekko wrote: Stuff
Thanks!
- Mister-Mind
-
Mister-Mind
- Member since: Jul. 1, 2006
- Offline.
-
- Forum Stats
- Member
- Level 07
- Blank Slate
I believe it too, you can use mysql to build it but you dont need it, you can build it straight off php.
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
I can't get it to work with:
.php file:
Your code up here somewhere.
<th scope="row"><span class="class"><.A. href="veiw.php?id=<?php echo $newid1; ?>">
<?php echo $newname1; ?></.A.></span><hr /></th>
And the text file as:
1|wicked name
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/27/06 06:31 PM, elbekko wrote: Does it give any errors?
Nope, just displays nothing. Must be an error creating the variables.
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
Why do you actually want to create such silly variables? Just echo from withing the foreach loop =)
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
If this makes it easier to understand:
5|name 5 - "5" should be $newid1 and "name 5" should be $newname1
4|name 4 - "4" should be $newid2 and "name 4" should be $newname2
3|name 3 - "3" should be $newid3 and "name 3" should be $newname3
2|name 2 - "2" should be $newid4 and "name 2" should be $newname4
1|name 1 - "1" should be $newid5 and "name 1" should be $newname5
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/27/06 06:38 PM, elbekko wrote: Why do you actually want to create such silly variables? Just echo from withing the foreach loop =)
Because $newid* is used for the link. Name is used for the name it shows on the portal.
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
Try doing it like this:
http://pastebin.ca/102746
You can change 30 to whatever the limit is of things you want to show. you just put this in your HTML =)
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/27/06 06:48 PM, elbekko wrote: Try doing it like this:
http://pastebin.ca/102746
You can change 30 to whatever the limit is of things you want to show. you just put this in your HTML =)
Thanks, that worked really well.
- JeremysFilms
-
JeremysFilms
- Member since: Feb. 18, 2005
- Offline.
-
- Forum Stats
- Member
- Level 18
- Blank Slate
At 7/27/06 05:47 PM, doodle_flash wrote: You won't beleive this untill its done, but i'm making a flash portal that works entirely on .dat/.txt files. NO MySQL.
What's the point of that? It'll just end up using up more bandwidth and server load in the end since it would have to always read the entire txt file and then pull sub-data from that and then turn it into variables. It's just a lot of un-needed work. MySQL and other databases use special algorithms and keys to find and select data. In the end, it'll be more work and more trouble to use txt files for everything. ALSO, when the files become full of a lot of data, everything will begin to become slower since it has to read the entire files and it will begin to take longer.
Do you even know MySQL though?.. if not, learn it.
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
Oh well.
I'm going to learn MySQL somewhen.
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/27/06 08:57 PM, BurgerBlock wrote:At 7/27/06 08:56 PM, doodle_flash wrote: Oh well.Read my sql and php tutorial in PHP: Main. It will help you get started.
I'm going to learn MySQL somewhen.
Sure.
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/27/06 08:57 PM, BurgerBlock wrote: Read my sql and php tutorial in PHP: Main. It will help you get started.
I've read so many SQL and MySQL tutorials.
What i don't understand is how do i get the database? Like make a file or something?
- DannyIsOnFire
-
DannyIsOnFire
- Member since: Apr. 14, 2005
- Offline.
-
- Forum Stats
- Member
- Level 21
- Movie Buff
At 7/27/06 09:05 PM, -Doodle- wrote:At 7/27/06 08:57 PM, BurgerBlock wrote: Read my sql and php tutorial in PHP: Main. It will help you get started.I've read so many SQL and MySQL tutorials.
What i don't understand is how do i get the database? Like make a file or something?
Ive never really learned MySQL (its on my to do list) but i tihnk it goes something like:
CREATE TABLE name_of_table_here(
bla_bla_bla
);
Dont take this as gospel though, since as i said, ive never really got to know MySQL to well.
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 7/28/06 04:10 AM, DannyIsOnFire wrote: Ive never really learned MySQL (its on my to do list) but i tihnk it goes something like:
CREATE TABLE name_of_table_here(
bla_bla_bla
);
Dont take this as gospel though, since as i said, ive never really got to know MySQL to well.
Do i type this in as a phpMyAdmin query?
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
Heheh, if you have phpMyAdmin, there's no need to do it manually ;)
Follow these easy steps:
• Go to phpMyAdmin
• You will see a textbox on the first page "Create new database", fill in the name of your DB and click "Create" (you can skip this if your host only gives you one database)
• Select your new (or existant) database from the drop-down menu on the left.
• In the right frame, scroll down untill you see a box titled "Create new table on database <x>"
• Fill it in, "name" is obvious and "fields" are the number of columns you want in your table. (no worries, this can all be changed later :))
• You come to a new screen that may look messy at first. Left column is for the names, second for datatype, third for length. If you have any experience with programming datatypes shouldn't be hard to understand. Remember, TEXT does not need a set length, as it is always at 64k.
• Click create, and you have your shiny table!
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- Jordan
-
Jordan
- Member since: Apr. 23, 2006
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]


