Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic setting of a variable

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
ok....time to drop back 20 yards and punt....let's start with the basics shall we.

I just want to now set a variable from dynamic content. How do I achieve this?

same scenario as last post...have a table being populated with a field in my DB. displaying four records at a time. If I click on a row, i want that value to populate into a variable.
 
To set a PHP variable, you'd need to submit the page back to the server, or load a page. Basically, you could do something like the following:

Code:
<a href="page.php?id=4">Click</a>

And then parse the query string using the global $_GET array.

Code:
<?
# this is the page.php page
$id = isset( $_GET['id'] ) ? $_GET['id'] : 0;
echo $id;
?>

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
but if i reload the page my table will start at the begining will it not? say i'm displaying records 5-8. If I click on record 6 and reload then my table gets refreshed as well and will then be displaying records 1-4. I would like for it to stay where it's at?
 
way too vague...

depending on how you're keeping the current state, you can do it all through the query string.

Code:
<a href="page.php?start=4&end=7>Click</a>

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
depending on the database, its possible to pull back a range, by putting on the end of your SQL query "Limit #,#" , first # being the start position, and second # being the number of records. For example if you want to pull back record 4 and the next 6 after it , 3, 6 ( because it's zero based, 0 is the first one so instead of 4 its 3 ).

So once you keep passing variables with your hyperlink, you can have it do

"Limit $start, $length"

Karl Blessing
PHP/MySQL Developer
 
forgive me for i am new to php....i'm not sure i follow.

if i have a db that has 13 records in it but only displaying four at a time. so...on load....recs 1-4 display. if i click NEXT, then 5-8 display. (9-12 and then 13 respectively)

Say I'm on the third set (9-12) I click on 10. the page will reload and start me back off at 1-4. however I want it to keep the display at 9-12. that way i dont have to scoll through the other records again.

does that explain it a little better?

thx
 
Yes. And the answer remains the same. When you click "Next", you're most likely passing a variables through the query string. If I am mistaken, then how are you retrieving the next 4 records?

Either way, you would pass the same variable with each <a>.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
You have to understand the basic nature of a PHP script and how web based applications work.
A PHP script is executed, the output is sent to the browser. Like in a phone call, the server hangs up. Conversation is over.
The client clicks something in the browser in the received document. The server receives the request and handles it without any memory of ever talking to you before - unless you provide the parameters the server should take in.
These parameters can be variables transmitted via POST or GET as well as cookie based data. One way of keeping variables over successive accesses is to use SESSIONS. In that case the vars are stored on the server and you can retrieve them by passing along the sessionID using cookies, GET params or similar. Other way is to attach GET parameters to the URLs which the server send to the client so appropriate offsets e.g. for browsing a database are possible.
A PHP application works very different from desktop apps. There is no consistent state.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top