Jump to content

Echoing out data individually


Thauwa

Recommended Posts

I have a table called 'items' and it has fields called name, cost and description.

When dynamically echoing out the values (ex: items.php), i have added an extra field called URL, which is a URL for

ex: page.php?item=table

Now, I get the URL by using the variables, but how do I design page.php, so as to display each record regarding 'table', i.e. name, description and cost.

The thing is that I need to display them individually.

 

And another thing that I want to know is how to paginate the records in 'items.php' (the example I used at first).

Thanks in advance for any help that you can offer.

Link to comment
https://forums.phpfreaks.com/topic/152349-echoing-out-data-individually/
Share on other sites

If you want to display the variables on page.php (passed via the URL), you use what's called $_GET.  For example:

 

echo $_GET['name'];
echo $_GET['cost'];

 

This is if you've called the page using a URL such as: page.php?name=Example&cost=10

Well it depends how you want to structure it and what the page is going to do with the variables.  Common practice is to pass the ID of the row in the table via the URL, and then on the receiving page use that ID to query the database.

 

Say we make this the URL: page.php?id=3

 

Then on page.php have something like:

 

$query = "SELECT * FROM `table` WHERE `id` = '" . mysql_real_escape_string($_GET['id']) . "'";

 

Using the URL to pass a unique identifier and then using that to retrieve the information you need from the table is common practice.

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.