Question:

MySQL and PHP Help, cant get details page to work.

by  |  earlier

0 LIKES UnLike

I set up a page which searched the database no problem and then I want to be able to link the search page to the details page for each of the results given, the problem is that no matter what you click, the details page only and always displays the first item in the database. my links for each of them seem to be correct because the address for each is details.php?resid=* and the resid seems fine. Any ideas what it could be?

 Tags:

   Report

2 ANSWERS


  1. Ok, if your links are containing the correct id then the problem is most likely in the details.php script.

    So what I would do is...

    Look for something like $_GET['resid'] or $_REQUEST['resid'] and verify the passed value is good.

    Then look for the sql string that is pulling the record from the db... something like...

    $sql = "SELECT * FROM details_table WHERE id=$_GET[resid]";

    There's really no telling how the script is dealing with the data without seeing it myself, but this should get you started...

    Basically, the moral is VERIFY the data... like, throw in a:

    echo 'GET: '.$_GET['resid'];

    echo 'SQL:'.$sql;

    Where $sql is whatever string the script is using to retrieve the record.

    Also, one thing I've run into in the past is database column type lengths...  this is a rare case but a previous programmer had set the assoc_id column to like int(4) and all the ids in the main table were int(11) so any time it would try to associate the int(11) id with the int(4) assoc_id it would pull the wrong data.

    Hope this helps a little.


  2. You need to run through the records in sequence each time you call the page and build a table to show the results. The link should be the ID number of each record. After this your details page should do something like :

    //table named search_items

    //each item having an auto_increment key field as id and text_field for //the text searched

    $search_result = mysql_query("select * from search_items where id = '$_GET[resid]'");

    while ($search_record = mysql_fetch_array($search_result)){

    $displaytext ="$search_record[text_field]";

    //This could include your oewn text formatting tags

    }

    echo $displaytext;

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions