HELP! display SQL query using a href code

Discussion in 'PHP' started by buknoii, Oct 13, 2007.

  1. #1
    hi there! i'm a newbie on php and i would like to ask on how to display the sql output correctly. It involves 2 php files and the codes are posted below.

    display.php

    echo "<a href=view_post.php?xval=";
    echo $row["incval"];
    echo ">";
    echo $row["item_title"];
    echo "</a>";



    view_post.php

    $result = mysql_query("select * from classified_postings where category ='xval'") or
    die (mysql_error());

    while ($row = mysql_fetch_array($result))

    {
    echo $row["date"];
    echo "<br>";
    echo $row["category"];
    echo "<br>";

    echo "<a href=view_post.php?xval=";
    echo $row["incval"];
    echo ">";
    echo $row["item_title"];
    echo "</a>";

    echo "<br>";
    echo $row["item_description"];
    echo "<br><br>";
    }

    mysql_free_result($result);


    any help would greatly be appreciated
     
    buknoii, Oct 13, 2007 IP
  2. buknoii

    buknoii Guest

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    help! please anyone :)
     
    buknoii, Oct 14, 2007 IP
  3. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Can you explain what you are trying to do and what the error is you are getting. From looking over your code I spotted this error:

    $result = mysql_query("select * from classified_postings where category ='xval'") 
    PHP:
    should be relaced with

    
    $xval = (int)$_POST['xval'];
    $result = mysql_query("select * from classified_postings where category ='$xval'");
    PHP:
    This is assuming that xval is a numeric value.

    Brew
     
    Brewster, Oct 14, 2007 IP
  4. buknoii

    buknoii Guest

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    geeez thanks for the help.. let me try the code :)
     
    buknoii, Oct 14, 2007 IP
  5. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #5
    What exactly is your question?

    Peace,
     
    Barti1987, Oct 14, 2007 IP
  6. ste.richards

    ste.richards Guest

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Are you trying to echo the query that you're sending to the SQL server?

    If so it may be worth trying storing the query as text in a variable, echoing the contents of the variable and then running mysql_query.

    $query = "select something from somewhere";
    echo $query;
    $query = mysql_query($query);
     
    ste.richards, Oct 14, 2007 IP