SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to fetch a list with links that make queries?

    The purpose is to make a list of articles with a title, and the titles are links to their description.
    The description is also a field in the database that can be queried.
    But how do I make these automatic links to new automatic made queries ?

    I have this for code:
    PHP Code:
    $makeList mysql_query("SELECT * FROM databasename ORDER BY id") or die(mysql_error());  
    echo 
    "<p>This is the list:</p>";
     
    while (
    $row mysql_fetch_assoc($makeList)) { 
    $id $row["id"];
    $name $row["name"];
    $title $row["title"];
    echo 
    "<p>"$name ." <a href=\""$description ."\">"$title ."</a> </p> \r\n";
       }
    mysql_close($connection);

    Last edited by bulevardi; Dec 16, 2008 at 07:31.

  2. #2
    Trash Boat mkoenig's Avatar
    Join Date
    Aug 2007
    Posts
    1,232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not the best at PHP but know my way around...

    Do you get errors?

    If so try...


    PHP Code:
    $makeList mysql_query("SELECT * FROM databasename ORDER BY id") or die(mysql_error());  

    echo 
    "<p>This is the list:</p>";

     

    while (
    $row mysql_fetch_assoc($makeList)) { 

    $id $row["id"];

    $name $row["name"];

    $title $row["title"];

    echo 
    "<p>$name <a href='$description'>$title</a></p>";

       }

    mysql_close($connection);



  3. #3
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, No I don't get errors, but I want to show a list with links in it.
    And those links (where I have $description now) have to call new queries or something...

    Like in this example:
    http://www.warre.gastmans.be/Lijst.aspx

    Or the links have to do something like this:
    {
    include('top.php');
    echo $description;
    include('bottom.php');
    }
    But I don't know how to put this into a <a href=" " >

  4. #4
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $makeList mysql_query("SELECT * FROM databasename ORDER BY id") or die(mysql_error());  
    echo 
    "<p>This is the list:</p>";
     
    while (
    $row mysql_fetch_assoc($makeList)) { 
    $id $row["id"];
    $name $row["name"];
    $title $row["title"];
    echo 
    "<p>"$name ." <a href=\"?function=showDescription\">"$title ."</a> </p> \r\n";
       }
    mysql_close($connection);
    }

    function 
    showDescription() {
    include(
    'top.php');
    echo 
    $description;
    include(
    'bottom.php');

    Also, if the function showDescription is inside this query (so before mysql_close), it doesn't work...

  5. #5
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So anyone knows?

    I got a query, for example: showing rows of 2 columns (name and title).
    And the title is in a link.
    But I want the link to call a new query that shows a description value of it.

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pass some type of value in the query string that will facilitate you being able to select a specific record.

    For example
    Code:
    <a href="script.php?id=597">see more</a>
    PHP Code:
    $id = (int) $_GET['id'];
    $sql "select foo from bar where id=$id"

  7. #7
    SitePoint Addict
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, if I do it like this, it works.

    PHP Code:
    echo "<p>$name <a href=\"new.php?id="$id ."\">"$title ."</a></p> \r\n"



    // here's the new page that gets the id... 

    $id $_GET['id'];

    $sql mysql_query("SELECT description FROM databasename WHERE id='$id'"
    // make the sql query that shows the description based on that ID. 
    But, another question about it:
    if you want to make the links doing other sql queries? Do you have to make two $_GET structures?
    Or do you have to implement this:

    PHP Code:
    echo "<p>$name <a href=\"new.php?fun=quer2&id="$id ."\">"$title ."</a></p> \r\n"

    if(
    $fun == "quer1" || $fun == "quer2" || $fun == "quer3") {

    $fun();

    function 
    quer1() {

    $id $_GET['id']

    $sql mysql_query("SELECT description FROM databasename WHERE id='$id'"
    // make the sql query that shows the description based on that ID.



    and with the POST method?
    Can you use the POST method only by forms? Or also by links?
    Because I don't want the values in my url.

    Something like this:
    echo "<p>$name <a href=\"????\" value=\"new.php?fun=quer2&id=". $id ."\" method=\"post\">". $title ."</a></p> \r\n";

    The rest:
    $id = $_POST['id']


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •