nclocl Posted August 19, 2011 Share Posted August 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/ Share on other sites More sharing options...
nclocl Posted August 19, 2011 Author Share Posted August 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259422 Share on other sites More sharing options...
Muddy_Funster Posted August 19, 2011 Share Posted August 19, 2011 this isn't an SQL issue, you need to remember that variable names are case specific: $question is not the same as $QUESTION Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259424 Share on other sites More sharing options...
nclocl Posted August 19, 2011 Author Share Posted August 19, 2011 Haha thank you, I work on Oracle all day and this is something I'm doing in my spare time. So in that case, say I clicked this url that I generated, how do I reference that in the select statement on the next page? Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259434 Share on other sites More sharing options...
Muddy_Funster Posted August 19, 2011 Share Posted August 19, 2011 use $id = $_GET['id']; this will take the value assigned to id in the URL and assign it to the new variable $id on the englishessays.php page. Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259440 Share on other sites More sharing options...
nclocl Posted August 19, 2011 Author Share Posted August 19, 2011 Perfect, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259453 Share on other sites More sharing options...
nclocl Posted August 19, 2011 Author Share Posted August 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259479 Share on other sites More sharing options...
nclocl Posted August 19, 2011 Author Share Posted August 19, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259486 Share on other sites More sharing options...
nclocl Posted August 19, 2011 Author Share Posted August 19, 2011 can anyone see what's wrong with this? Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1259587 Share on other sites More sharing options...
fenway Posted August 21, 2011 Share Posted August 21, 2011 Wrong how? Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1260275 Share on other sites More sharing options...
Muddy_Funster Posted August 22, 2011 Share Posted August 22, 2011 Watch your quotes, you you havn't ended the href: echo "<a href=\"englishessays.php?id=$id>"; should read echo "<a href=\"englishessays.php?id=$id\">"; also, you don't need to run as many echo's, 1 would do it: echo "<a href=\"englishessays.php?id=$id\">$question</a><br><br>"; Quote Link to comment https://forums.phpfreaks.com/topic/245202-displaying-records-that-link-to-row-data/#findComment-1260415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.