|
|
|
|
|
|
|
![]() |
#1 |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
PHP help needed
Hi, I have a little problem figuring out what to do here. First let me explain my goal.
To display 1 tgp gallery, then 1 free site, then 1 tgp gallery, then 1 free sites, and on and on until there are no new tgp galleries or free sites. Im pulling the tgp galleries from tgplinks.txt and the free sites from fslinks.txt. heres a snippet from one of those txt files: http://www.tgpgallery.com/gallery-01.html||A TGP Gallery Description Goes Here||Teen| http://www.tgpgallery.com/gallery-02.html||A TGP Gallery Description Goes Here||Babe| http://www.tgpgallery.com/gallery-03.html||A TGP Gallery Description Goes Here||Hardcore Sex| The empty spaces are for future use. Heres the php code im using to do this: <?php $fslinks=file("fs-Mixed.txt"); $tgplinks=file("tgp-Mixed.txt"); $numfs=count($fslinks); $numtgp=count($tgplinks); if($numfs>=$numtgp){ for($i=0;$i<$numfs;$i++){ $fs=explode("|",$fslinks[$i]); $tgp=explode("|",$tgplinks[$i]); print(" <a href=$fs[0]>$fs[4]</a><br>$fs[2]<br><br>\n <a href=$tgp[0]>$tgp[4]</a><br>$tgp[2]<br><br>\n"); } }elseif($numtgp>=$numfs){ for($i=0;$i<$numtgp;$i++){ $fs=explode("|",$fslinks[$i]); $tgp=explode("|",$tgplinks[$i]); print(" <a href=$tgp[0]>$tgp[4]</a><br>$tgp[2]<br><br>\n <a href=$fs[0]>$fs[4]</a><br>$fs[2]<br><br>\n"); } } php?> This code does great if there are the same number of lines on both txt files. But if, for example, tgplinks.txt has 50 lines and fslinks.txt has only 20 then i get a wierd looking page. It basically looks like this: TGP gallery, blah blah Free Site, blah blah TGP gallery, blah blah TGP Gallery, blah blah TGP Gallery, blah blah The little snippet doesnt realize I want it to stop entering the fslinks.txt stuff and just go with the tgplinks.txt when it runs out. So... my question is, can anyone tell me how to fix this? I need to tell php that once the lines run out on fslinks.txt (or tgplinks.txt) that it should just leave the line out instead of filling the info in with blanks like this <a href="http://blahblah">Whatever TGP</a> blah blah<br><br>/n <a href=""></><br><br>/n I think through all the rambling I got the correct question out there. Anyone know how to fix this?
__________________
Submit Your TGP Galleries |
![]() |
![]() |
![]() |
#2 |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
When I was describing my problem I figured out the solution. I was making it more difficult than it actually was. I just needed to add another if in there inside the for loop.
if($i <= ($numfs-1)) {
__________________
Submit Your TGP Galleries |
![]() |
![]() |
![]() |
#3 |
If there is nobody out there, that's a lot of real estate going to waste!
Join Date: Dec 2003
Posts: 2,177
|
Actually your code will still be a little screwy.
If #TGPs = #FS then they will be displayed with both loops. Your >= and <= overlap. Look at this PHP Code:
|
![]() |
![]() |
![]() |
#4 |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
oh, oops. thanks for catching that.
__________________
Submit Your TGP Galleries |
![]() |
![]() |
![]() |
#5 |
If there is nobody out there, that's a lot of real estate going to waste!
Join Date: Dec 2003
Posts: 2,177
|
NP, I've been at it for 30+ years. Those things just jump out at me automatically now.
|
![]() |
![]() |
![]() |
#6 |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
asdf
Thanks tickle
![]() PHP Code:
![]()
__________________
Submit Your TGP Galleries |
![]() |
![]() |
![]() |
#7 |
If there is nobody out there, that's a lot of real estate going to waste!
Join Date: Dec 2003
Posts: 2,177
|
if($i < $numtgp) {
if($i < $numfs) { Still a small problem with these, they should be using <= Personally I don't like nested elseif groups. They tend to get confusing when you get into multiple levels. Also I prefer using spilt() to place the record into named fields like $linkHref, $linkDesc, rather than array buckets. A little easier to remember what is what, when you get down a few 100 lines of code later. |
![]() |
![]() |
![]() |
#8 | |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
Quote:
Actually I ended up just using your code... its alot cleaner than mine and its easy to expand when I decide to expand it. Right now theres just tgp and fs but I want to have add premium and avs and blogs eventually. With my code it would be a mess but with yours its pretty simple ![]() Thanks Tickler WB
__________________
Submit Your TGP Galleries |
|
![]() |
![]() |
![]() |
#9 |
Wheither you think you can or you think you can't, Your right.
|
If your doing/learning php, it could be good to learn mysql with php, can be a little easier coding and more fun, least to me. I am sure no expert, but php/mysql is a great combination, better then using text files.
ronnie |
![]() |
![]() |
![]() |
#10 | |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
Quote:
![]() The PHP book I bought only has a tiny bit on MySQL. Not that the book has been much use anyways. I need something that was written by an idiot so I can follow alone |goodidea I mostly just learn from looking at other peoples scripts and figuring out how it works from there (I guess thats how alot of people learn it). Eventually I will get into MySQL but for now Im trying to learn this adult webmastering thing so my php learning is sort of at a stand still. From what Ive seen php + MySQL is definately the way to go though.
__________________
Submit Your TGP Galleries |
|
![]() |
![]() |
![]() |
#11 | |
Wheither you think you can or you think you can't, Your right.
|
Quote:
ronnie |
|
![]() |
![]() |
![]() |
#12 |
If there is nobody out there, that's a lot of real estate going to waste!
Join Date: Dec 2003
Posts: 2,177
|
Check out the SQLite that is built into PHP. You don't need SQL on your server.
|
![]() |
![]() |
![]() |
#13 |
If something goes wrong at the plant, blame the guy who can't speak English
Join Date: May 2006
Posts: 306
|
Hey tickler, Ill have to check out that SQLite, Ive never even heard of it before.
Ronnie, yep, its a painfully slow way to learn ![]() Ive been thinking about taking some classes if I ever get ahead enough.
__________________
Submit Your TGP Galleries |
![]() |
![]() |
![]() |
#14 |
Rock stars ... is there anything they don't know?
Join Date: Jun 2006
Posts: 10
|
seems like way to much thought/work is used above...
$input = preg_replace ( "/\r\n|\r|\n/", "\n", $fslinks'); $Array = explode("\n", $input); foreach ($Array as $item) { list($url, $var1, $description, $var2, $cat, $var3) = explode("|", $item); // go to work |
![]() |
![]() |
![]() |
Thread Tools | Search this Thread |
Display Modes | Rate This Thread |
|
|