Be Excellent To Each Other

And, you know, party on. Dude.

All times are UTC [ DST ]




Reply to topic  [ 52 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Less Simple PHP problem
PostPosted: Thu Mar 10, 2011 1:53 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
OK. I've got myself confused as to what variables are interfering with each other here.
Trying to display a 'next page' link when there is more than one page, or the $moreresults variable is true. That bit's fine. The first page you're on does not know what page number it is, but subsequent pages do because they GET it from the previous page.

How can I make the first page you're on know it is page1 so that subsequent pages know what to +1 or -1 from?What am I doing wrong here?

Code:
$thisPage = 1;
if (!empty($_GET)) {
$thisPage = $_GET['page'];
}

if ($page>1 OR $thisPage>1 OR $moreResults)
{
if ($thisPage>1 OR $page>1) echo '<TD align="left"><a href="result.php?category=',$cat,'&amp;page=',$thisPage-1,'">Previous page</a>';
if ($moreResults=='1') echo '<a href="result.php?category=',$cat,'&amp;page=',$thisPage+1,'">Next page</a>';
}


EDIT: I tried adding in this bit in the middle to say "if page isn't set yet, then make it 1", but that still doesn't work.
Code:
$thisPage = 1;
if (!empty($_GET)) {
$thisPage = $_GET['page'];
}

if (!$page) {$page=1; $thisPage=1;}

if ($page>1 OR $thisPage>1 OR $moreResults)
{
if ($thisPage>1 OR $page>1) echo '<TD align="left"><a href="result.php?category=',$cat,'&amp;page=',$thisPage-1,'">Previous page</a>';
if ($moreResults=='1') echo '<a href="result.php?category=',$cat,'&amp;page=',$thisPage+1,'">Next page</a>';
}

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 8:26 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
$page is never being set.
Also, avoid using !empty($_GET) in case something else is in there - use if (!$_GET['page']} instead.

Shouldn't the "moreresults" if statement be outside the "if page is greater than one" statement? Otherwise nothing will display on the first page.

Pretty sure you can ditch the first if statement entirely.
Just print the opening <td> before you check for the contents.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 10:20 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
On a PC now!
Here is what I'd do, assuming $moreResults is being set at some point before this. Not sure what the difference between $page and $thisPage is either.
Code:
$thisPage = 1;
if (!$_GET['page']) {
    $thisPage = $_GET['page'];
}

if (!$page) {
   $page=1;
   $thisPage=1;
}

if (1 < $page || 1 < $thisPage) {
    echo '<TD align="left"><a href="result.php?category=',$cat,'&amp;page=',$thisPage-1,'">Previous page</a>';
}
if ($moreResults) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$thisPage+1,'">Next page</a>';
}

Note that there's no real need to put the if statements in braces - that's just me. Putting the comparisons the way around that I did (ie. constants first) is good practice, however.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 10:46 
User avatar
Legendary Boogeyman

Joined: 22nd Dec, 2010
Posts: 8175
My pagination code looks like this. It might be shit.

Code:
if (!$_GET['startpoint']) {
   $startpoint = 0;
}
   
if (($startpoint - 30) >= 0) {
?>
<a href="<?php echo $baseURL; ?>page.php?startpoint=<?php echo ($startpoint - 30); ?>">&lt;&lt;&lt; Previous 30 results </a>

<?php
} // end if

if (($startpoint + 30) < $numrows) {
?>
<a href="<?php echo $baseURL; ?>page.php?startpoint=<?php echo ($startpoint + 30); ?>">Next 30 results &gt;&gt;&gt; </a>
<?php
} // end if
?>
<h2>Pages: <?php

$pag = 1;
while($pag <= ceil($numrows/30)) {
   if ($startpoint == (($pag * 30)-30)) {
      echo "&nbsp;<strong>$pag</strong>&nbsp;";
   }
   else {
      echo "&nbsp;<a href=\"".$baseURL."page.php?startpoint=" . (($pag * 30)-30) . "\">$pag</a>&nbsp;";
   }
   $pag++;
} // end while
?></h2>               


Where $numrows is the total number of results in the original query, and $startpoint is the LIMIT offset in the mySQL query. All of the above assumes 30 results per page so adjust as necessary.

_________________
Mr Kissyfur wrote:
Pretty much everyone agrees with Gnomes, really, it's just some are too right on to admit it. :)


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 14:40 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
I don't even know why there's a difference between page and thispage, so I changed all instances of thispage to bum:
Code:
         $bum = 1;
         if (!empty($_GET)) {
            $bum = $_GET['page'];
         }

if (!$page) {$page=1; $bum=1;}

if (1 < $page || 1 < $bum) {
    echo '<TD align="left"><a href="result.php?category=',$cat,'&amp;page=',$bum-1,'">Previous page</a>';
}
if ($moreResults) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$bum+1,'">Next page</a>';
}

echo 'bum = ',$bum,'';
echo 'page = ',$page,'';


but bum and page always seem to output to 1. Am I not sending the +1 to the variables across properly?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 14:48 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
That's because there's no $page, so you're always setting it (and $bum) to 1 on the line
Code:
if (!$page) {$page=1; $bum=1;}


Why not just get rid of $bum entirely?
Code:
$page = 1;
if (!$_GET['page']) {
    $page = $_GET['page'];
}

if (1 < $page) {
    echo '<TD align="left"><a href="result.php?category=',$cat,'&amp;page=',$page-1,'">Previous page</a>';
}
if ($moreResults) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$page+1,'">Next page</a>';
}

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 14:57 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Looks neater, but still no worky.

On the very first page you access, it assumes itself to be page zero, because $page doesn't exist yet. So it tries to +1 to $page, and 0+1=1 and it advances to page 1.

I want the first page you land on to set itself as page 1, so that when the $moreResults variable is 1 it takes $page, and adds 1 to it. I am going to stab myself in the face soon.

Thanks for your help so far with this, by the way. Don't want to seem ungrateful.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 14:59 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
First line is $page = 1; ?

Are you sure $_GET['page'] isn't set to zero (or null)?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:01 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Mr Russell wrote:
Don't want to seem ungrateful.

S'aright, you don't.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:01 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
FUCK
Code:
if (!$_GET['page']) {
should obviously be
Code:
if ($_GET['page']) {

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:04 
User avatar
Part physicist, part WARLORD

Joined: 2nd Apr, 2008
Posts: 13421
Location: Chester, UK
Grim... wrote:
FUCK
Code:
if (!$_GET['page']) {
should obviously be
Code:
if ($_GET['page']) {


I did wonder about that, but I don't know PHP and thought I was being a moron. Oh well!


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:12 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Haha!!!!
YEEEEEESSS!

That bastard little exclamation mark! 13 hour turnaround for this one. Thank you!

OK, so now to improve my own knowledge: that code manages to implement +1 or -1 to page, and pass that to the next page. Why does "$page = 1;" not reset it to 1 every time?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:13 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Because you overwrite it with $_GET['page'] (if $_GET['page'] has a value) on the next line.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:14 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Also, it's not quite right yet, as you're going to have problems with your table if you're on page 1, as the open table cell won't appear:
Code:
echo '<TD align="left">';
if (1 < $page) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$page-1,'">Previous page</a>';
}
if ($moreResults) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$page+1,'">Next page</a>';
}
is better. Make sure to close the <td> somewhere, too!

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:21 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
Also, it's not quite right yet, as you're going to have problems with your table if you're on page 1, as the open table cell won't appear:
Code:
echo '<TD align="left">';
if (1 < $page) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$page-1,'">Previous page</a>';
}
if ($moreResults) {
    echo '<a href="result.php?category=',$cat,'&amp;page=',$page+1,'">Next page</a>';
}
is better. Make sure to close the <td> somewhere, too!


At the moment, I'm not bothered by wonky table code. Actually, I stripped the rest of the table code out before presenting it here, but I missed that opening TD :)
I'll have a fiddle later once I get the pagination working everywhere though, supercheers.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:27 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
No worries!

You should probably check to make sure $_GET['page'] is an integer, too

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:33 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
No worries!

You should probably check to make sure $_GET['page'] is an integer, too

I tried editing the URL to say page=r and it just returned no results, so I should be fine with that if people are going to start typing stuff in the address bar, right?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:39 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
As long as it never goes near a database, I guess.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:48 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
As long as it never goes near a database, I guess.


The only thing it ever goes near is some XML output. I have no desire to go near databases with php yet. It scares me enough doing 'delete from' statements in SQL!

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:50 
User avatar
Comfortably Dumb

Joined: 30th Mar, 2008
Posts: 12034
Location: Sunny Stoke
Grim... wrote:
Why not just get rid of $bum entirely?


Ah, you're a $breast man?

_________________
Consolemad | Under Logic
Curse, the day is long
Realise you don't belong


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 15:55 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
devilman wrote:
Grim... wrote:
Why not just get rid of $bum entirely?


Ah, you're a $breast man?


$breast+1

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Thu Mar 10, 2011 16:03 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
$breast ++;

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:29 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
OK. trying to sort out the wonky search results now. I need to refresh the page, or call the exact same page again, but change only one variable.
I can get the page to refresh, and I can get the variable to pass, but I can't get it to keep the other variables the same.
Code:
   


So I've taken the $dvdtitle from the input of the form on the previous page and set it. But when I reload the page to try and set $sorttype it loses the value of $dvdtitle (and indeed probably all the other variables I've set on the page).

Any ideas where I should be looking, or is $_SERVER['PHP_SELF' along the wrong lines entirely?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:39 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
$_SERVER['PHP_SELF'] is just the name of the current file.
So, on this page, it would be viewtopic.php, and I suspect it's fine for what you are trying to do.

Is it going wrong when you click on a 'best match' / 'popular' link, or when you hit the search button?

Either way, I'm itching to blame the if (empty($_POST)) bits, because they're just not right. For instance, if $_POST['cities'] is set but $_POST['sorttype'] isn't, then $sorttype will never be set.
This:
Code:
         if (empty($_POST)) {
            $dvdtitle = $_GET['title'];
         } else {
            $dvdtitle = $_POST['INPUT'];
         }

         if (empty($_POST)) {
            $mediatype = $_GET['mediatype'];
         } else {
            $mediatype = $_POST['cities'];
         }

         if (empty($_POST)) {
            $sorttype = $_GET['sorttype'];
         } else {
            $sorttype = $_POST['sorttype'];
         }
is the same as
Code:
         if (empty($_POST)) {
            $dvdtitle = $_GET['title'];
            $mediatype = $_GET['mediatype'];
            $sorttype = $_GET['sorttype'];
         } else {
            $dvdtitle = $_POST['INPUT'];
            $mediatype = $_POST['cities'];
            $sorttype = $_POST['sorttype'];
         }
which is surely not what you want?


To get around this you could make the form method="get", so everything is a get, or you could do something like
Code:
if (!$_POST['sorttype']) {
    $sorttype = $_GET['sorttype'];
} else {
    $sorttype = $_POST['sorttype'];
}
for each variable.
Actually - what's $_POST['INPUT']? Is that from the previous page?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:43 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Anyhow, for debugging fun, right at the top of your page, put:
Code:
print "GET: <pre>";
print_r($_GET);
print "</pre>POST: <pre>";
print_r($_POST);
print "</pre>";

And you should be able to work out the problem (if not, post the results here).

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:44 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Yeah, POST[input] takes the actual content that is typed in and passes it to be encoded as $dvdtitle. You can tell I have no idea what I'm doing with this. I hate cobbling together stuff from other people's code.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:46 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
If someone chooses something from the select dropdown, then $_POST won't be empty, which means the code is going to try and set $dvdtitle with $_POST['INPUT'], when it really wants to be $_GET['title'] (and $mediatype with $_POST['cities'], but that's never being passed through from your form or your links anyway).

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:48 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
Anyhow, for debugging fun, right at the top of your page, put:
Code:
print "GET: <pre>";
print_r($_GET);
print "</pre>POST: <pre>";
print_r($_POST);
print "</pre>";

And you should be able to work out the problem (if not, post the results here).


Damn. That means that the code actually is passing the correct title/sorttype through, because the variables are both set (using either the text links OR the form). But for some reason then it is not sending them off to the URL to add the variables onto the end of the URL that outputs the XML.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:50 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Output the three variables ($dvdtitle , $mediatype, $sorttype) right before the $dvdtitle = urlencode($dvdtitle); line, and I bet you'll find they're not set to what you want.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:52 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
You'll want something like this before your serviceURL, which sets the variables and encodes them at the same time:
Code:
if ($_GET['title']) {
   $dvdtitle = urlencode($_GET['title']);
} else {
   $dvdtitle = urlencode($_POST['INPUT']);
}


if ($_GET['mediatype']) {
   $mediatype = urlencode($_GET['mediatype']);
} else {
   $mediatype = urlencode($_POST['cities']);
}

if ($_GET['sorttype']) {
   $sorttype = urlencode($_GET['sorttype']);
} else {
   $sorttype = urlencode($_POST['sorttype']);
}

$thisPage = 1;
if ($_GET['page']) {
   $thisPage = $_GET['page'];
}

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:55 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
You could do the ifs in shorthand too, if you wanted, but I've never liked it myself:
Code:
$dvdtitle = ($_GET['title'] ? urlencode($_GET['title']) : urlencode($_POST['INPUT']));
$mediatype = ($_GET['mediatype'] ? urlencode($_GET['mediatype']) : urlencode($_POST['cities']));
$sorttype = ($_GET['sorttype'] ? urlencode($_GET['sorttype']) : urlencode($_POST['sorttype']));

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 0:58 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
OK. So the variables are passing, but I'm kind of hard coding them by putting them in the URL. So why is the serviceURL not being activated the second time around?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:00 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Did you output $dvdtitle, $mediatype and $sorttype (like I said somewhere in the mess of all my posts on the last page ;) )?

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:02 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Yeah. $dvdtitle and $sorttype seem to be fine because I'm using

echo ' <a href="', $_SERVER['PHP_SELF'],'?title=',$dvdtitle,'&sorttype=bestmatch">bestmatch</a>';
echo ' <a href="', $_SERVER['PHP_SELF'],'?title=',$dvdtitle,'&sorttype=popular">popular</a>';

which hard codes them in. Mediatype I'm not setting either way at the minute, which is the next hurdle.

After those variables are set though, it should send them off to get an XML result back, but the results aren't changing this end, so something's not working yet.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:04 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Okay then, next step - before the '// call the service, the returned XML is in $Page' comment, output $serviceURL and see what it says.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:08 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
Okay then, next step - before the '// call the service, the returned XML is in $Page' comment, output $serviceURL and see what it says.


Before it it returns nothing.
After it it returns the full URL, but $sorttype is NOT being set. It is leaving it in the URL as "&sort=$sorttype" which is the defaults from above. So I can pass it, but not set it?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:09 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Haha fucking hell :)

Code:
$serviceURL .= '$sorttype';
should be
Code:
$serviceURL .= $sorttype;

No quotes.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:12 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
Haha fucking hell :)

Code:
$serviceURL .= '$sorttype';
should be
Code:
$serviceURL .= $sorttype;

No quotes.


HA! I bloody love you.
You remember when I said nobody had explained to me the difference between
$variable
',$variable,'
'.$variable.'

....yeah.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:14 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
OK. Two follow up questions:

1) Is there are more elegant way to preserve the variables then? if I ended up making them all user selectable (eg. pagesize as well) then I'm going to have to hardcode them ALL into the URL.

2) I'm using TextPad. Is there a better editor that highlights the different bits of PHP to stop me making stupid mistakes like this?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:19 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
1) You could store them in a database or cookie but that's overkill - the way you're doing it is fine. To make life easier, rather than putting them into the form action URL, put them in hidden variables instead, like this:
Code:
print '<input type="hidden" value="'.$dvdtitle.'" name="dvdtitle(or whatever)" />';
inside the form. That way you won't mix up your $_GETs and your $_POSTs.
2) I used to use TextPad, it's okay. Do you have the syntax highlighting?
You could give Aptana a try.
However, nothing would have helped with the above, as it wasn't actually an error - the code was doing what you told it. Putting something inside single quotes in PHP means "this is what I want it to be, leave it alone".

When debugging, just throwing every variable you've got onto the screen before and after the point where something goes wrong will show you the problem, 99% of the time.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:23 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
One last quick point - you're encoding the urls each time the page is submitted. That means that something that starts off "Turner & Hooch" will become "Turner%20%26%20Hooch", which is what you want.
However, if they submit the page again, it'll be "Turner%2520%2526%2520Hooch" (I think), which isn't right, obviously.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:44 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
One last quick point - you're encoding the urls each time the page is submitted. That means that something that starts off "Turner & Hooch" will become "Turner%20%26%20Hooch", which is what you want.
However, if they submit the page again, it'll be "Turner%2520%2526%2520Hooch" (I think), which isn't right, obviously.


So I can use decode URL .... after the servicepage call?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:45 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Not really - you need to decode them before you encode them - you can't decode something that hasn't been encoded (unless there's a film called %20 that I don't know about).

So
Code:
$dvdtitle = urlencode(urldecode($dvdtitle));
etc.

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:49 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
Not really - you need to decode them before you encode them - you can't decode something that hasn't been encoded (unless there's a film called %20 that I don't know about).

So
Code:
$dvdtitle = urlencode(urldecode($dvdtitle));
etc.


Oh cool, I can mix them.

If people didn't add examples to the PHP manual I'd still be making a logo.

You're ace! Go to bed! Thank you!

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:50 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Mr Russell wrote:
Oh cool, I can mix them.

You can nest as many functions as you like - all you're actually doing is encoding the decode of the variable.

I will surely go to bed in a few minutes.
About 3, actually...

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:51 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Grim... wrote:
I will surely go to bed in a few minutes.
About 4, actually...


You're watching Buffy?

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:51 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Mr Russell wrote:
Grim... wrote:
I will surely go to bed in a few minutes.
About 4, actually...


You're watching Buffy?

Doing some uploading.
2:44!

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 1:55 
SupaMod
User avatar
Est. 1978

Joined: 27th Mar, 2008
Posts: 69689
Location: Your Mum
Done! Bed!

_________________
Grim... wrote:
I wish Craster had left some girls for the rest of us.


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 2:10 
User avatar
Slightly Brackish

Joined: 28th Jan, 2011
Posts: 1198
I'm still awake so if you have any more problems I'm happy to help :)

_________________
Current games: Luxor 2, Boom Boom Rocket


Top
 Profile  
 
 Post subject: Re: Less Simple PHP problem
PostPosted: Sun Mar 13, 2011 2:24 
Awesome
User avatar
Yes

Joined: 6th Apr, 2008
Posts: 12329
Alberto wrote:
I'm still awake so if you have any more problems I'm happy to help :)


Sure, get it to set $sorttype=popular as default before I overwrite it with my form.

_________________
Always proof read carefully in case you any words out


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 52 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Columbo, Squirt and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search within this thread:
You are using the 'Ted' forum. Bill doesn't really exist any more. Bogus!
Want to help out with the hosting / advertising costs? That's very nice of you.
Are you on a mobile phone? Try http://beex.co.uk/m/
RIP, Owen. RIP, MrC. RIP, Dimmers.

Powered by a very Grim... version of phpBB © 2000, 2002, 2005, 2007 phpBB Group.