Welcome! Log In Create A New Profile

Advanced

Walkthrough Two - Build your own PHP Survey/Poll Application

Posted by 77928490 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Walkthrough Two - Build your own PHP Survey/Poll Application
March 15, 2013 10:16AM
Hi Mac,

My question is about the primary/foreign key passed between the two tables, i.e.: 'tblquestions' and 'answers' in this section.

In tablquestions it is quite clear how question 4 is pulled from the table,i.e. include 'sqlSurvey.php';.

However in the answers table we are SET-ting a column A,B or C. So my question is how does mysql know which row in the answers table needs to be incremented by 1if we only indicate a column? How is the QID passed to the answers table? I just don't see it.

Thanks
Ian
Re: Walkthrough Two - Build your own PHP Survey/Poll Application
March 21, 2013 07:18PM
of all the 13 chapters and the 3 walkthroughs this topic i had to revisit, in light of 77928490 concern i am also finding myself wondering in some coding suspenses. Not sure if i
exactly understand the question being asked but from the database point of view the QID in tbquestions has qa, qb and qc, if u notice QID in the answers tables also has QID with respectives
3 answers, the link should should be there. I think the sql query
Language: PHP
<?php $qnum =';4';; $sql = "select * FROM tblquestions.QID = ';$qNum';; ?>
is how it shoud get pulled but thats just for question 4 only as you suggested, not yet fully confident with all the codings but i think thats a start, not sure what the others think

..&ru..
avatar Re: Walkthrough Two - Build your own PHP Survey/Poll Application
March 22, 2013 07:06AM
Really enjoyed coding for graph, simple but effective, good to know that logic can produce colour! Find these walkthroughs very helpful.
avatar
Mac
Re: Walkthrough Two - Build your own PHP Survey/Poll Application
March 22, 2013 08:13AM
77928490 Wrote:
-------------------------------------------------------
> Hi Mac,
>
> My question is about the primary/foreign key
> passed between the two tables, i.e.:
> 'tblquestions' and 'answers' in this section.
>
> In tablquestions it is quite clear how question 4
> is pulled from the table,i.e. include
> 'sqlSurvey.php';.
>
It can be confusing (and is).... best way is to run it all as opposed to just reading through it (not saying that is what you are doing).

Add the Vote to the Database page explains it, although they acknowledge that they are taking shortcuts

Language: PHP
$selected_radio = $_GET[';q';]; // This just gets which radio button was clicked. The value comes from the HTML form, and will be A, B or C. This is then placed into the variable called $selected_radio. // $selected_radio will then have the value A or B or C   $SQL = "UPDATE answers SET $selected_radio = $selected_radio + 1";   //e.g. SET $selected_radio =.... is now SET A =..... $SQL = "UPDATE answers SET A = $selected_radio + 1";
Sorry, only registered users may post in this forum.

Click here to login