thebassettman
thebassettman

Reputation: 17

Two SQL queries, only the first returns any results

So, I have a piece of code where I'm trying to pull out two lists of results from two different tables in my database.

However, when I run the code, the first SQL statement works perfectly ( with $NumberOfUsers echoing as 3) but the second appears to not be entering the while loop at all ($NumberOfSkills always echos as 0 where it should be echoing as 6).

I've already tried using a value other than $row in the second while loop condition, but that didn't seem to make a difference.

$GetAllUsernamesSQLStatement="SELECT Username,Name FROM users WHERE Manager=0";
$GetAllUsernamesQuery=mysql_query($GetAllUsernamesSQLStatement);
$NumberOfUsers=0;
while ($row = mysql_fetch_assoc($GetAllUsernamesQuery)){
    $Username[$NumberOfUsers]=$row['Username'];
    $Name[$NumberOfUsers]=$row['Name'];
    $NumberOfUsers++;
}
echo $NumberOfUsers;
$GetAllSkillsSQLStatement="SELECT SkillName FROM skills";
$GetAllSkillsQuery=mysql_query($GetAllSkillsSQLStatement);
$NumberOfSkills=0;
while ($row = mysql_fetch_assoc($GetAllSkillsQuery)){
    $Skill[$NumberOfSkills]=$row['SkillName'];
    $NumberofSkills++;
}
echo $NumberOfSkills;

Both SQL statements have been pasted into the database, I'm using (phpmyadmin) and work correctly there.

Upvotes: 0

Views: 62

Answers (1)

Pawel Mansfeld
Pawel Mansfeld

Reputation: 104

Change $NumberofSkills++; to $NumberOfSkills++;

PHP variables are case sensitive.

Upvotes: 2

Related Questions