Jump to content

[SOLVED] Displaying data from different rows on different pages


Casual-T

Recommended Posts

Hi, I am working on a news system with a MySQL database, of course.

 

Right now, the news system undergoes a series of three pages:

1. Page with the news form to be processed.

2. Page that processes the form, inserts all the info into the DB, writes to a new file, and redirects the user to a page with a link to their newly created file.

3. Page that displays the information that was filled out in page 1 and is also the page that the user is taken to when they click on their link in page 2.

 

What I need to know is, how can I display data on each new "Page 3" that is created and is relevant to the information that was filled out for that specific page.

 

For example, if a user fills out the news form, a link and a "Page 3" will be created that displays the information they filled out from Page 1. Then, when they go back and fill out the news form again, the new page should display information that is DIFFERENT from the first posting.

 

Right now, my issue is that every "Page 3" that is created shows the information from each instance of posting, when I only want it to show the information from when that page was posted.

 

If it helps, I have a "news_id" column that basically just auto-increments when something new is posted. Right now, the number in that column is up to 91 since I've tested it so many times.

 

I hope anyone can help and that you understand what is going on here :P

Link to comment
Share on other sites

I am not using sessions. I did try using a session for this, but that only pulled the same information on each new page that was created.

 

I figure that SELECTING specific rows from the database to be displayed would be much easier and efficient.

 

I would like to stick to "SELECTING" from the database instead of using a session, but if I did switch back to a session and track the news_id column like you said, do you think it will remember the data that was posted for each news posting?

Link to comment
Share on other sites

each newly created news_id is stored as a new row in the database. I will save this post so I can edit it when I have more time so that I can provide a screenshot of the table and hopefully provide more details

Yes, I know that... I mean if you want to "get it back" on another page you need to create continuity -- which means storing something you can use to get it back.

Link to comment
Share on other sites

each newly created news_id is stored as a new row in the database. I will save this post so I can edit it when I have more time so that I can provide a screenshot of the table and hopefully provide more details

Yes, I know that... I mean if you want to "get it back" on another page you need to create continuity -- which means storing something you can use to get it back.

 

But it IS being stored.... in the database. That way I can pull the information from the DB to be displayed on whatever page I want (i.e. getting it back)

 

I don't seem to understand what you're wanting me to store  ::)

Link to comment
Share on other sites

Right now, my issue is that every "Page 3" that is created shows the information from each instance of posting, when I only want it to show the information from when that page was posted.

Since your scripts can't be "psychic", you need to "store" the news_id from the most recent Page 1 submission.  Your DB will not help you here.

Link to comment
Share on other sites

I found some other help online and it was suggested to me that I store the news title in the URL of each news link (using $_GET), that way every Page 3 will display the title from that specific posting.

 

My only issue now is that the Page 3's are not showing the information from the news_text column. The way I have it is as follows:

 

<?php 

$id=$_GET['title'];  //get the title from the url

$info_query = "SELECT news_text FROM news WHERE news_title=$id";

$info = mysql_query($info_query);

echo $id;
echo $info;
?>

 

Technically, it is supposed to show the information in the news_text column that is related to the news_title, but it is only showing the news_title.

Link to comment
Share on other sites

mysql_query() returns a resource... not sure what you're expecting without calling fetch_array().  Also, that script is vulnerable to sql injection.  Maybe you should take a look at some of the stickies that have tutorials.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.