Jump to content

Need help with $_SERVER['PHP_SELF']


paradoxmime

Recommended Posts

I have a list of 'products' on a page and each row has a button I can select to put the product available or unavailable from searches. The problem, more like an issue is that it refreshes the page. This is a pain when I'm working at the bottom of the list. I have to scroll back down everytime I make a change. Anyway to keep everything right where it was?

Link to comment
https://forums.phpfreaks.com/topic/187464-need-help-with-_serverphp_self/
Share on other sites

Simple Method

You could use link anchors to jump down to where you were after submitting.

 

Complex Method

You could use a mix of JavaScript to update the value without refreshing the page.

 

The Way I Would Do It

I'd make it a check box and then put an "Update" button at the very bottom of the page, when you submit the form it loops through all the checkboxes and changes their values accordingly :)

So how would I do that with this:

 

if($plan_active == 1)
            	{
            		echo " <a href=".$_SERVER['PHP_SELF']."?active_id=$Plan_ID&active_value=0&page=".$_GET['page']."&orderid=".$_GET['orderid']."&asc=".$_GET['asc']."><img src=\"gif/green.gif\" border=0></a>";
                     
                  
            	}
            	else 
            	{
            		echo " <a href=".$_SERVER['PHP_SELF']."?active_id=$Plan_ID&active_value=1&page=".$_GET['page']."&orderid=".$_GET['orderid']."&asc=".$_GET['asc']."><img src=\"gif/red.gif\" border=0></a>";
                   
                   
            	}

This precedes the code you have already looked at:

 

$coloriter = 0;
        while($row = mysql_fetch_array($result)) {
        	
            ## tri to set bgcolor of row
        	$color = ($coloriter % 2) ? "#edefda" : "#CCCC99";
            
        	## get last date modded
            if(trim($row['Date_Modded']) == "0000-00-00")
            {
                $modded = "Never";
            }
            else 
            {
                $modded = $row['Date_Modded'];
            }
            #######################################################
            ## set $Plan_ID to current plan id in loop
            $Plan_ID = $row['Plan_ID'];
            #
            ## set Plan_Number to current plan_number in loop
            $Plan_Number = $row['Plan_Number'];
            #
            ## SET $plan_active to public field in db
            $plan_active = $row['Public'];
            ######################################################
		$Plan_sales = $row['Sales_PDF'];
		$Plan_review = $row['Review_PDF'];
		######################################################
		$Plan_garage = $row['Garage_Location'];
		######################################################
            echo '<tr bgcolor="' , $color , '">';
            ## added a </td> to close the field in the line below
            if ($row['Elevation'] <> "") {
			echo '<td bgcolor="FFFFFF" width="250"><img src="http://'.$_SERVER["HTTP_HOST"].'/Designers/'.$_SESSION["Des_ID"].'/jpg/' . str_replace('.jpg', '_small.jpg', $row['Elevation']) . '" /><br><div class="blue"><strong>TGC-'.$row['Plan_ID'].' '.$row['Garage_Location'].'</strong></div></td>';
			} else { // no imageecho 
			echo '<td align="center" bgcolor="FFFFFF" width="250">Image not provided</td>';
			}
            ## added new column for activated plans
            	echo '<td align="center">';

Alright so $Plan_ID is the unique identifier, perfect :)  Lets make some changes then.

 

This can all be done within your <a> tag so this is what the line should look like (varying depending on your if/else statement):

 

echo " <a href=".$_SERVER['PHP_SELF']."?active_id=$Plan_ID&active_value=0&page=".$_GET['page']."&orderid=".$_GET['orderid']."&asc=".$_GET['asc']."#$Plan_ID name=$Plan_ID><img src=\"gif/green.gif\" border=0></a>";

 

Give that a shot :)

 

The name=$Plan_ID so every link is unique, so that when you use #$Plan_ID on the end of the URL it will jump down to that link.

 

Hopefully that'll solve your issues.

Ok, I realize that creating a bookmark does help a little but it doesn't quite do the trick. The reason for this is because if you are halfway down the page and click on the submit button, the page refreshes and then the line I was working on is now at the top of the page! I have seen pages where changes were made and everything remained exactly where it was. Maybe there is an alternative to using $_SERVER['PHP_SELF'] ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.