Jump to content


Photo

nested query into 3 tables


  • Please log in to reply
2 replies to this topic

#1 SOLID

SOLID
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 24 June 2006 - 07:14 AM

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

Question 1
option1 - answer
option2 - answer
option3 - answer

Question 2
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
<?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++;
    }
}

I hope thats not too confusing?? sorry i usually use Coldfusion.
Thanks in advance for your help

#2 SOLID

SOLID
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 June 2006 - 02:32 AM

Can anyone point me in the right direction as to what im doing wrong here??

Please help ..

#3 jajtiii

jajtiii
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts

Posted 25 June 2006 - 02:48 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users