Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2006-06-04, 01:14 PM   #1
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
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
WarBot is offline   Reply With Quote
Old 2006-06-04, 01:26 PM   #2
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
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
WarBot is offline   Reply With Quote
Old 2006-06-04, 03:14 PM   #3
tickler
If there is nobody out there, that's a lot of real estate going to waste!
 
tickler's Avatar
 
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:
$numfs=count($fslinks);
$numtgp=count($tgplinks);
$maxLoop $numtgp;
if(
$numfs $numtgp) {
$maxLoop $numfs;
}

for(
$i=0;$i<$maxLoop;$i++){

if(
$i <= $numtgp) {
$tgp=explode("|",$tgplinks[$i]);
print(
"<a href=$tgp[0]>$tgp[4]</a><br>$tgp[2]<br><br>\n");
}
if(
$i <= $numfs) {
$fs=explode("|",$fslinks[$i]);
print(
"<a href=$fs[0]>$fs[4]</a><br>$fs[2]<br><br>\n");
}


__________________
Latina Twins, Solo, NN, Hardcore
Latin Teen Cash
tickler is offline   Reply With Quote
Old 2006-06-04, 09:05 PM   #4
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
Join Date: May 2006
Posts: 306
oh, oops. thanks for catching that.
__________________
Submit Your TGP Galleries
WarBot is offline   Reply With Quote
Old 2006-06-04, 09:29 PM   #5
tickler
If there is nobody out there, that's a lot of real estate going to waste!
 
tickler's Avatar
 
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.
__________________
Latina Twins, Solo, NN, Hardcore
Latin Teen Cash
tickler is offline   Reply With Quote
Old 2006-06-04, 11:22 PM   #6
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
Join Date: May 2006
Posts: 306
asdf

Thanks tickle This is what i finally came up with.

PHP Code:
<?php


$fslinks
=file("fs-Mixed.txt");
$tgplinks=file("tgp-Mixed.txt");

$numfs=count($fslinks)-2;
$numtgp=count($tgplinks)-2;

if(
$numfs>=$numtgp){
    for(
$i=0;$i<$numfs;$i++){
            if(
$i $numtgp) { 
                print(
"
                    
$fslinks[$i]<br><br>\n
                    
$tgplinks[$i]<br><br>\n");
            }else{
                print(
"
                    
$fslinks[$i]<br><br>\n");
            }
    }
}elseif(
$numtgp>$numfs){
    for(
$i=0;$i<$numtgp;$i++){
            if(
$i $numfs) { 
                print(
"
                    
$tgplinks[$i]<br><br>\n
                    
$fslinks[$i]<br><br>\n");
            }else{
                print(
"
                    
$tgplinks[$i]<br><br>\n");
            }
    }
}

php?>
Works perfectly
__________________
Submit Your TGP Galleries
WarBot is offline   Reply With Quote
Old 2006-06-05, 08:12 AM   #7
tickler
If there is nobody out there, that's a lot of real estate going to waste!
 
tickler's Avatar
 
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.
__________________
Latina Twins, Solo, NN, Hardcore
Latin Teen Cash
tickler is offline   Reply With Quote
Old 2006-06-05, 10:29 PM   #8
ronnie
Wheither you think you can or you think you can't, Your right.
 
Join Date: Jun 2004
Location: midwest
Posts: 2,274
Send a message via ICQ to ronnie
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
ronnie is offline   Reply With Quote
Old 2006-06-06, 07:56 AM   #9
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
Join Date: May 2006
Posts: 306
Quote:
Originally Posted by tickler
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.

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
WarBot is offline   Reply With Quote
Old 2006-06-06, 08:06 AM   #10
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
Join Date: May 2006
Posts: 306
Quote:
Originally Posted by ronnie
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
Hey Ronnie

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
WarBot is offline   Reply With Quote
Old 2006-06-06, 09:44 AM   #11
tickler
If there is nobody out there, that's a lot of real estate going to waste!
 
tickler's Avatar
 
Join Date: Dec 2003
Posts: 2,177
Check out the SQLite that is built into PHP. You don't need SQL on your server.
__________________
Latina Twins, Solo, NN, Hardcore
Latin Teen Cash
tickler is offline   Reply With Quote
Old 2006-06-06, 10:27 AM   #12
ronnie
Wheither you think you can or you think you can't, Your right.
 
Join Date: Jun 2004
Location: midwest
Posts: 2,274
Send a message via ICQ to ronnie
Quote:
Originally Posted by WarBot
Hey Ronnie

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.
Thats the way I learned, little at time and looking at other scripts, plus playing around. It sure takes time. I personally think it's easier to mess with data in MySQL than flat files, but that could just be me. When your doing simple things, like pulling links, actually MySQL is pretty easy and simple.

ronnie
ronnie is offline   Reply With Quote
Old 2006-06-06, 06:33 PM   #13
WarBot
If something goes wrong at the plant, blame the guy who can't speak English
 
WarBot's Avatar
 
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 I wish I would have gotten into computers and scripting fresh out of highschool (20 years ago...). I dont want to look back 20 years from now and say "I wish I would have... 20 years ago" so Im learning it now. Slowy but surely. Just not enough time to really dig into it so I have to chip away at it little by little.

Ive been thinking about taking some classes if I ever get ahead enough.
__________________
Submit Your TGP Galleries
WarBot is offline   Reply With Quote
Old 2006-06-07, 06:24 PM   #14
FakeTextTGP
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
__________________
Sincerely,
FakeTextTgp

FakeTextTGP is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:04 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc