Jump to content

nested query into 3 tables


SOLID

Recommended Posts

Hi Everyone, Im new to php and only been using it for a couple of months now.
Im having some trouble with a db query?

I have 3 tables questions, answers & selections

Im trying to get an output like this

[b]Question 1[/b]
option1 - answer
option2 - answer
option3 - answer

[b]Question 2[/b]
option1 - answer
option2 - answer
option3 - answer

I do get the question and the option to display but not the answer?? im not sure what i am doing wrong.

There is an error being thrown..
Warning: mysql_query(): A link to the server could not be established in /index.php on line 84
Access denied for user: 'root@localhost' (Using password: NO)
I have highlighted the line like this ############

heres the code
[code]
<?php
include("include/dbConnect.php");
mysql_connect($fasthit,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM $dbQs WHERE year = $yr";
$result = mysql_query($query) or die("unable to get data");
$num = mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$Qid=mysql_result($result,$i,"Qid");
$question=trim(mysql_result($result,$i,"question"));
$type=trim(mysql_result($result,$i,"type"));
// WRITE QUESTION
echo "<p><b>".$question."</b></p>";

// GET OPTION
mysql_connect($fasthit,$user,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $Squery = "SELECT * FROM $dbS WHERE parent_id = $Qid";
    $Sresult = mysql_query($Squery) or die(mysql_error());
    $Snum = mysql_num_rows($Sresult);
    mysql_close();
    $S=0;
    while ($S < $Snum) {
    $option=mysql_result($Sresult,$S,"option");
            
    echo $option." ";

        // GET SELECT BOX ANSWER
        include_once ("include/dbConnect.php");

############ error here???? ############
        mysql_connect($fasthit,$user,$password);

        @mysql_select_db($database) or die( "Unable to select database");
        $SSquery = "SELECT COUNT(*) AS itIS FROM $dbAs WHERE Qid = $Qid";
        $SSresult = mysql_query($SSquery) or die(mysql_error());
        mysql_close();
        echo $itIS."<br>";
    $S++;
    }
}
[/code]

I hope thats not too confusing?? sorry i usually use Coldfusion.
Thanks in advance for your help
Link to comment
Share on other sites

check your dbConnect file. It appears that it is not setting the correct values for your mysql connection validation. In fact, it appears that those variables are coming out to be null, so you're trying to connect with no username or pw.

mysql then assumes you're coming in as root with no pw, which does not authenticate.
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.