Jump to content

Displaying Records that link to row data


nclocl

Recommended Posts

I have a mysql table QUESTIONS with rows CREATED_BY, QUESTION and SUBJECT.

 

I have pages on a website that insert rows into this table depending on user input but now I would like to know how to display it.

 

I need a page with a list of questions (SELECT QUESTION FROM QUESTIONS) but they need to be hyperlinks that open a new page which displays that question and a text box to write an answer.

 

So my question is: How do I dynamically display the QUESTION records as hyperlinks?

 

When this is clicked I presume I can just post the question name and then on the next page, generate data based on this value from my table.

Link to comment
Share on other sites

For reference, this is what I tried:

 

<?
                            session_start();
                            if (!session_is_registered(email)) {
                                header("location:login.html");
                            }



                            $con = mysql_connect("blah", "blah", blah");

                            if (!$con) {

                                die('Connection Failed' . mysql_error());
                            }

                            mysql_select_db("blah", $con);

                            $result = mysql_query("SELECT * FROM QUESTIONS")
or die(mysql_error());

while($essay_data=mysql_fetch_array($result)){

$question = $essay_data['QUESTION'];

echo "<a href=\"englishessays.php?id=$question>";
echo "$QUESTION </a>";
echo "<br><br>";
}

                            ?>

 

I should probably add an ID number for each question I guess.  It doesn't work anyway.

Link to comment
Share on other sites

Just quickly, what's wrong with this?

 

while($essay_data=mysql_fetch_array($result)){

$question = $essay_data['QUESTION'];
$id = $essay_data['ID'];

echo "<a href=\"englishessays.php?id=$id">";
echo "$question </a>";
echo "<br><br>";
}}

 

It seems to be enclosing the 'echo' commands in the quotes.

 

The way I did it before worked but was adding </a>";

echo "<br><br>" as text onto the link

Link to comment
Share on other sites

agh sorry for the triple post.  Here's my code:

 

$result = mysql_query("SELECT * FROM ESSAY_QUESTIONS WHERE SUBJECT = 'ENGLISH'")
or die(mysql_error());

while($essay_data=mysql_fetch_array($result)){

$question = $essay_data['QUESTION'];
$id = $essay_data['ID'];

echo "<a href=\"englishessays.php?id=$id>";
echo "$question </a>";
echo "<br><br>";
}

 

It seems to display the first question as a link but the link itself looks like it is the rest of the data in the results.  How do I echo a link for each row rather than one link with everything on it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.