Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Displaying data from different MYSQL rows on different pages
Old 05-10-2009, 06:33 PM Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
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 at that point in time?

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
casual-t is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-10-2009, 11:50 PM Re: Displaying data from different MYSQL rows on different pages
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I'm not entirely sure of what you mean. Does all the previous records (the 91 records) show on "Page 3"? And you only want to show the one that were just added?

If not, I think you're gonna have to explain a bit clearer.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-11-2009, 02:47 PM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
No and Yes.

The news_id column (with the 91 records) should NOT show up on page 3. That column is simply just to keep track of each posting and hopefully be used to reference or pull the data relevant to the news_id number that was added for each posting.

I want every new "Page 3" that is created to only display the information that was filled out in the form at the time of the creation of that specific Page 3 (using "fopen" and "fwrite" commands to write to a new file) so that every new "Page 3" that is created/posted will have different information compared to all preceding Page 3's that were posted.
casual-t is offline
Reply With Quote
View Public Profile
 
Old 05-12-2009, 12:01 AM Re: Displaying data from different MYSQL rows on different pages
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Writing to a file? I thought you were using a database?
And I still dont see the problem. Exactly what is shown on Page3, and what do you want to show instead? Perhaps you could an example output.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-12-2009, 09:57 PM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
I'm doing both, writing to a file and storing the information that is written to that file in a database.

When the user submits the form, a new file is created and written to (so that Page 2 can link to those new files). That information is also inserted into the database so that it can actually be displayed on the new files that are created.

Right now, all of my Page 3's shows every row that was submitted to the database, but I want each Page 3 to only show the row that was created at the time of each specific news post.

Hope that helps. If not, I can probably provide a screenshot or graphical representation
casual-t is offline
Reply With Quote
View Public Profile
 
Old 05-13-2009, 02:56 AM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
I have created this graphical representation to hopefully clarify things:

http://www.shaunmilodesigns.com/newsformlayout.jpg (1440x900 resolution)
casual-t is offline
Reply With Quote
View Public Profile
 
Old 05-13-2009, 03:45 AM Re: Displaying data from different MYSQL rows on different pages
Skilled Talker

Posts: 55
Name: Brian
Trades: 0
this may be rough, but i think it could help you..

im not sure how your getting the links on page2, but you want them to contain a variable to pass to the next page, for example:

$links_query = "SELECT news_title FROM news";
$links = mysql_query($links_query);

while($row = mysql_fetch_array($links, MYSQL_ASSOC))
{
echo '<a href="domain.com\page.php?title=' . $row['news_title'] . '">' . $row['news_title'] . '</a>';
}

so this should loop through your database and create links of titles, with the title in the link as a variable

next on page 3, use the variable to get info about that link:

<?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;

so this isnt exactly perfect, but i hope it gives you an idea of how to get where your going.
bmp99 is offline
Reply With Quote
View Public Profile
 
Old 05-13-2009, 02:12 PM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
For the most part, that is pretty much how my links are set up on page 2 right now.

However, I will try your suggestion for page 3. I never would have thought to use $_GET so I'll try it out and let you know if it works out.
casual-t is offline
Reply With Quote
View Public Profile
 
Old 05-13-2009, 04:57 PM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
Here's a status update:

First of all, I love you bmp99. :P

However, the Page 3's are only showing the titles and not the news text.

I'm musing the following line of code like you suggested, but for some reason it doesn't seem to be pulling the news_text from the row with that specific news_title

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

Last edited by casual-t; 05-13-2009 at 04:59 PM..
casual-t is offline
Reply With Quote
View Public Profile
 
Old 05-14-2009, 12:05 AM Re: Displaying data from different MYSQL rows on different pages
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Now I understand :P
I wasn't really following because of the writing to file thing, because it isn't necesarry. Using a GET variable like this is the "normal" way of acomplishing what your trying to do. Normally you would use an ID value to point out a specifik entry in your database, and send that value as a GET variable (giving you an url like page3.php?id=12345). The ID is usually an integear of length 5-10, depending on how many entries you're expecting to get in the future.

The ID should (in your database) be set as the primary key for faster searches, and to retrieve data from an entry, you can use

SELECT * FROM news WHERE newsID='$id'

Then, only one page3 is needed, instead of creating a new one for every entry.
Also, remember to esacpe the GET variable before using it your query. Search for "SQL injection" for more info.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-14-2009, 08:27 AM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
Alright, so if I'm going to use the ID instead of the title in the URL, what should I define the $id variable as? How will the form submission tell the $id variable what value it should be?

Would it just be $_GET['id'] ? If so, then doesn't there have to be something in the form that gives it a number for the ID, much like it gave the value for "title"?
casual-t is offline
Reply With Quote
View Public Profile
 
Old 05-14-2009, 11:16 PM Re: Displaying data from different MYSQL rows on different pages
Novice Talker

Posts: 10
Trades: 0
Nevermind, it all seems to be working now. Thank you guys for your help!

Now to work on an image upload script...joy!
casual-t is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Displaying data from different MYSQL rows on different pages
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.85069 seconds with 12 queries