|
PHP - List Help! |
|
Steven2k3 (20:30 21/4/2003) Matthew (22:29 21/4/2003) Gulli (17:39 24/4/2003) Matthew (19:20 24/4/2003) Gulli (11:48 25/4/2003) ksattic (18:12 24/4/2003) Matthew (19:24 24/4/2003) ksattic (19:55 24/4/2003) Kinetic (20:03 24/4/2003) takkaria (11:16 25/4/2003) Kinetic (15:28 26/4/2003) takkaria (17:42 26/4/2003) Kinetic (17:57 26/4/2003) Hertzsprung (12:21 29/4/2003) Hertzsprung (16:46 26/4/2003) Kinetic (17:15 26/4/2003) jmb (17:23 26/4/2003) Hertzsprung (12:21 29/4/2003) Matthew (11:01 25/4/2003) ksattic (14:36 25/4/2003)
|
|
Steven |
Message #40261, posted by Steven2k3 at 20:30, 21/4/2003 |
Member
Posts: 1
|
I'm creating my own eCommerce shopping cart page... along with a search and categories... all that good stuff... Well Ive been learning PHP here resently... ive been working on it for about a week. I desided not to use mySQL for database becuz i didnt feel like learning how to use it and i wanted an easyer way to add and edit information.... so i created my own database. I simply created an HTML file with forms and tyed it with some PHP that takes the information and joins it together. It looks something like this after its joined:
================================================== item.file: ================================================== 0001:Item One:Items:This is Item One:123.45 0002:Item Two:Items:This is Item Two:678.90 0003:Item Three:Items:This is Item Three:567.89 ==================================================
Now I take that information and split it into different variables and the split thoughs variables in to more variables:
================================================== $file="item.file"; $open = fopen($file, "r"); $contents = fread($open, filesize($file));
list($item[1], $item[2], $item[3]) = split("\n", $contents);
$i=1; $count = count($item);
while ($i <= $count):
list($category[$i], $name[$i], $price[$i], $description[$i], $keywords[$i])= split(":",$item[$i]);
$i++;
endwhile; ==================================================
This works, but it wont work the way i need it. I have:
"list($item[1], $item[2], $item[3]) = split("\n", $contents);"
but i need the variables after list to be universal. Like the number of variables are determind by the number of items found in the "item.file".
Please tell me if there is a better way or how to do it this way.
Thanx!
Jellystand Owner Steven Malone (Contact@jellystand.com)
(www.Jellystand.com) |
|
[ Log in to reply ] |
|
Matthew Somerville |
Message #40264, posted by Matthew at 22:29, 21/4/2003, in reply to message #40261 |
Posts: 520
|
I'm creating my own eCommerce shopping cart page... I have no idea what this has to do with RISC OS programming, but hey.
Firstly, you can replace your splits with explodes (why were you using split on something that's not in any way a regular expression?). Secondly, look into the foreach loop, rather than using a while loop with count and lots of nasty indices.
Then for the thing you're actually asking, replace your "list($item[1], $item[2], $item[3]) = split("\n", $contents);" with the rather simpler "$item = explode("\n",$contents);"
Or, even simpler, simply replace the first four lines with $item = file('item.file') - file reads a file into an array all at once. I think you should do some more reading of PHP functions, they make your life much easier. |
|
[ Log in to reply ] |
|
Gunnlaugur Jonsson |
Message #40398, posted by Gulli at 17:39, 24/4/2003, in reply to message #40261 |
Member
Posts: 138
|
Replace the entire code with:
$contents = file("item.file");
You should be able to access everything within the $contents array by calling $contents[0][1] if I remember correctly (don´t have PHP here to test it).
Another way is to use $line_in_list = explode(":",$contents[$i]); and then use: echo $line_in_list[$x];
Instead of the while ... endwhile loop, check out the foreach() function in PHP, much simpler.
[Edited by Gulli at 18:52, 24/4/2003] |
|
[ Log in to reply ] |
|
Simon Wilson |
Message #40401, posted by ksattic at 18:12, 24/4/2003, in reply to message #40261 |
Finally, an avatar!
Posts: 1291
|
I have successfully programmed a shopping-cart system with PHP and MySQL, and RISC OS is a great development platform if the MySQL server is held on an external Unix/Windows box.
I really wouldn't recommend using text files if you can avoid it. SQL is perfect for sorting and searching. It's really not that difficult to learn - you can figure it out in a matter of days. |
|
[ Log in to reply ] |
|
Matthew Somerville |
Message #40405, posted by Matthew at 19:20, 24/4/2003, in reply to message #40398 |
Posts: 520
|
Replace the entire code with:
$contents = file("item.file"
You should be able to access everything within the $contents array by calling $contents[0][1] if I remember correctly (don´t have PHP here to test it). No, file will simply put each line of the file in an element of the $contents array. It doesn't make a multi-dimensional array.
[snip rest]
Hmm, my reply of three days ago seemed to say exactly the same things... |
|
[ Log in to reply ] |
|
Matthew Somerville |
Message #40406, posted by Matthew at 19:24, 24/4/2003, in reply to message #40401 |
Posts: 520
|
RISC OS is a great development platform if the MySQL server is held on an external Unix/Windows box. So without an external box, it's useless. I did use to develop a MySQL website solely on my RISC OS box, simply uploading to the remote server to test. This was only okay with university speed access to the internet. Now I have MySQL installed along with Apache, phpMyAdmin etc. on this laptop, I don't know how I ever managed to test and develop on RISC OS... |
|
[ Log in to reply ] |
|
Simon Wilson |
Message #40407, posted by ksattic at 19:55, 24/4/2003, in reply to message #40406 |
Finally, an avatar!
Posts: 1291
|
So without an external box, it's useless. Pretty much.
Though the webserver is running on RISC OS (Webjames) and so is PHP. PHP connects to the DB via my local network. I actually prefer Webjames to MS IIS for various reasons - it can handle more multiple connections (WinXP Pro IIS is crippled) and there are no security issues.
Now I have MySQL installed along with Apache, phpMyAdmin etc. on this laptop, I don't know how I ever managed to test and develop on RISC OS... PHPMyAdmin runs fine with Oregano2, and I prefer Zap to any Windows/*nix text editor, hence my choice!
I do my graphics work using software of my own design on RISC OS. |
|
[ Log in to reply ] |
|
Andrew Duffell |
Message #40408, posted by ad at 20:03, 24/4/2003, in reply to message #40407 |
Posts: 3262
|
I just spotted this thread, and I have to agree that mySQL is the best option. I refused to learn it until recently becasue I thought it was easier not to, but since learning it everything has become a whole lot easier
Andrew |
|
[ Log in to reply ] |
|
Matthew Somerville |
Message #40429, posted by Matthew at 11:01, 25/4/2003, in reply to message #40407 |
Posts: 520
|
I actually prefer Webjames to MS IIS for various reasons Where did I mention IIS? I would never use that... No, I've installed Apache, which is the same as my host uses, which makes testing far easier.
- it can handle more multiple connections (WinXP Pro IIS is crippled) and there are no security issues. ...that you know of. Have you been through every line of the source code personally?
PHPMyAdmin runs fine with Oregano2 Again, though, if you don't already own a PC and have a local network, rather pointless. Might as well run it on the server.
, and I prefer Zap to any Windows/*nix text editor, hence my choice! I do miss Zap, but a brilliant text editor doesn't unfortunately make up for the lack in lots of other areas... |
|
[ Log in to reply ] |
|
Andrew Sidwell |
Message #40431, posted by takkaria at 11:16, 25/4/2003, in reply to message #40408 |
Member
Posts: 324
|
I just spotted this thread, and I have to agree that mySQL is the best option. Don't rule out stuff other than MySQL. I recently hit problems using MySQL in a bug-tracking system I'm writing, and I'm going to switch to Postgres soon. Also, Firebird (www.firebird.org) looks quite good for a database.
MySQL doesn't support as much of the SQL spec as Postgres, either. |
|
[ Log in to reply ] |
|
Gunnlaugur Jonsson |
Message #40437, posted by Gulli at 11:48, 25/4/2003, in reply to message #40405 |
Member
Posts: 138
|
Replace the entire code with:
$contents = file("item.file"
You should be able to access everything within the $contents array by calling $contents[0][1] if I remember correctly (don´t have PHP here to test it). No, file will simply put each line of the file in an element of the $contents array. It doesn't make a multi-dimensional array.
I stand corrected!
[snip rest]
Hmm, my reply of three days ago seemed to say exactly the same things... Hmm, read it again and I agree! My original reply seems pretty much do more damage than good Guess I should knock myself in the head a couple of times |
|
[ Log in to reply ] |
|
Simon Wilson |
Message #40447, posted by ksattic at 14:36, 25/4/2003, in reply to message #40429 |
Finally, an avatar!
Posts: 1291
|
...that you know of. Have you been through every line of the source code personally? No - but there are still no security issues with it, till some fool decides to write an exploit. |
|
[ Log in to reply ] |
|
Andrew Duffell |
Message #40474, posted by ad at 15:28, 26/4/2003, in reply to message #40431 |
Posts: 3262
|
I just spotted this thread, and I have to agree that mySQL is the best option. Don't rule out stuff other than MySQL. I recently hit problems using MySQL in a bug-tracking system I'm writing, and I'm going to switch to Postgres soon. Also, Firebird (www.firebird.org) looks quite good for a database.
MySQL doesn't support as much of the SQL spec as Postgres, either. You could easily write a shopping cart with mySQLs features. Also mySQL is free. |
|
[ Log in to reply ] |
|
James Shaw |
Message #40480, posted by Hertzsprung at 16:46, 26/4/2003, in reply to message #40408 |
Ghost-like
Posts: 1746
|
I just spotted this thread, and I have to agree that mySQL is the best option. I refused to learn it until recently becasue I thought it was easier not to, but since learning it everything has become a whole lot easier
Andrew PostgreSQL MySQL |
|
[ Log in to reply ] |
|
Andrew Duffell |
Message #40483, posted by ad at 17:15, 26/4/2003, in reply to message #40480 |
Posts: 3262
|
I just spotted this thread, and I have to agree that mySQL is the best option. I refused to learn it until recently becasue I thought it was easier not to, but since learning it everything has become a whole lot easier
Andrew PostgreSQL MySQL FreeMoney |
|
[ Log in to reply ] |
|
JMB |
Message #40486, posted by jmb at 17:23, 26/4/2003, in reply to message #40483 |
Member
Posts: 467
|
Since when was BSD != free? |
|
[ Log in to reply ] |
|
Andrew Sidwell |
Message #40487, posted by takkaria at 17:42, 26/4/2003, in reply to message #40474 |
Member
Posts: 324
|
You could easily write a shopping cart with mySQLs features. Also mySQL is free. Yes, you could. Doesn't mean it's a particluarly good idea. Also, Postgres is free. |
|
[ Log in to reply ] |
|
Andrew Duffell |
Message #40489, posted by ad at 17:57, 26/4/2003, in reply to message #40487 |
Posts: 3262
|
You could easily write a shopping cart with mySQLs features. Also mySQL is free. Yes, you could. Doesn't mean it's a particluarly good idea. Also, Postgres is free. Ah.. I didn't know postgresql was free |
|
[ Log in to reply ] |
|
James Shaw |
Message #40821, posted by Hertzsprung at 12:21, 29/4/2003, in reply to message #40486 |
Ghost-like
Posts: 1746
|
Since when was BSD != free? Long time ago when it belonged to Berkeley University... is that right? |
|
[ Log in to reply ] |
|
James Shaw |
Message #40822, posted by Hertzsprung at 12:21, 29/4/2003, in reply to message #40489 |
Ghost-like
Posts: 1746
|
You could easily write a shopping cart with mySQLs features. Also mySQL is free. Yes, you could. Doesn't mean it's a particluarly good idea. Also, Postgres is free. Ah.. I didn't know postgresql was free Yes. And it rocks. Big time. And MySQL sucks. Big time. |
|
[ Log in to reply ] |
|
|