DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Automatically updated link and page

By: | 18 Feb 2009 4:25 pm

Hello,

here is a news table:

id - date - title - par1- text body

For example, here is the code for displaying latest 10 entries:

select * from newsa ORDER BY id DESC LIMIT 10

while ($row = mysql_fetch_ array($query) ) {
echo"<p> " . $row[`date`] . $row[`title` ] . "</p>".
"<p> " . $row[`par1`] ."</p>"."<a href=`testdisplay2. php`>(more...)</a>" ; }

How do you make "(more....)" link you see above which will come up with each separate result be an automatically updated link to that generic php / sql query page that will bring up the correct article? right now as you see, (more...) link is only pointing to a page called testdisplay2, which is not good, because it is the same for all results that come up.

Or another example for the same kind of problem: lets say there is a search query that searches the database for certain keywords and brings up the headings of articles that contain that search word...Then I want user to click on that heading and be directed to the php page that will automatically display that relevant article..
There is no separate page for each entire article. Just one generic php page that generates entire article once it is called. If I had a separate page for each entire article then it would be easy but that option is much more time consuming. In other words, how will that one generic php page whihc display the entire article, "know" which article heading has been clicked in the first page and generate the corresponding article?

Thanks in advance...

Comments

Taking your last example first, what you are looking for is what might be called a 4-page database system. You need a page to do each of the following functions:

* Show a single article based on the id number using GET variables (eg script.php?id=91) with suitable validation to prevent abuse. The script validates the GET query number, looks it up and displays the data in your preferred format. Watch out for SQL injection opportunities. In this case force the number into an integer with floor() or some other function.

* Search page which submits to itself and shows matching results as links to the above type of page. Action part of <form> tag points to the script itself; method should be POST. Script looks at form data to devise query (watch for SQL injection) and any results are shown at the top of the page a la Google search. Be kind to your users and show the form again with the search term entered. This will allow them to edit the search if they get too many or too few results. Note that htmlentities() is helpful to process the string for the
value property of the <input> tag. The stripslashes() function may be needed as well.

* add a new entry (if appropriate)

* edit an entry (if appropriate)
Regarding your more results link, here you will need to decide if the new entries will be coming in often. If they are, you may want to save the search results (ie matching id numbers in a session variable). If they are not coming in very often then you can code the skip and view values for the LIMIT skip, view clause of your SQL query. Maybe you will know how many to view so you only need to pass along the skip value as a GET variable.

By: | 18 Feb 2009

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move