Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   PHP help needed (http://www.greenguysboard.com/board/showthread.php?t=31976)

WarBot 2006-06-04 01:14 PM

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:



$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("
$fs[4]
$fs[2]

\n
$tgp[4]
$tgp[2]

\n");
}
}elseif($numtgp>=$numfs){

for($i=0;$i<$numtgp;$i++){
$fs=explode("|",$fslinks[$i]);
$tgp=explode("|",$tgplinks[$i]);
print("
$tgp[4]
$tgp[2]

\n
$fs[4]
$fs[2]

\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

Whatever TGP blah blah

/n



/n

I think through all the rambling I got the correct question out there. Anyone know how to fix this?

WarBot 2006-06-04 01:26 PM

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)) {

tickler 2006-06-04 03:14 PM

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>$tgp[2]\n");
}
if(
$i <= $numfs) {
$fs=explode("|",$fslinks[$i]);
print(
"<a href=$fs[0]>$fs[4]</a>$fs[2]\n");
}




WarBot 2006-06-04 09:05 PM

oh, oops. thanks for catching that.

tickler 2006-06-04 09:29 PM

NP, I've been at it for 30+ years. Those things just jump out at me automatically now.

WarBot 2006-06-04 11:22 PM

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]\n
                    
$tgplinks[$i]\n");
            }else{
                print(
"
                    
$fslinks[$i]\n");
            }
    }
}elseif(
$numtgp>$numfs){
    for(
$i=0;$i<$numtgp;$i++){
            if(
$i $numfs) { 
                print(
"
                    
$tgplinks[$i]\n
                    
$fslinks[$i]\n");
            }else{
                print(
"
                    
$tgplinks[$i]\n");
            }
    }
}

php?>

Works perfectly |roses|

tickler 2006-06-05 08:12 AM

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.

ronnie 2006-06-05 10:29 PM

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

WarBot 2006-06-06 07:56 AM

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

WarBot 2006-06-06 08:06 AM

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|waves|

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.

tickler 2006-06-06 09:44 AM

Check out the SQLite that is built into PHP. You don't need SQL on your server.

ronnie 2006-06-06 10:27 AM

Quote:

Originally Posted by WarBot
Hey Ronnie|waves|

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

WarBot 2006-06-06 06:33 PM

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.

FakeTextTGP 2006-06-07 06:24 PM

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


All times are GMT -4. The time now is 04:22 AM.

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