0

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.

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • are your $NumberOfSkills and $NumberofSkills variables case sensitive? – NathanFrasier Apr 02 '18 at 21:46
  • 1
    @Nanos https://stackoverflow.com/questions/33273941/php-case-sensitivity – Don't Panic Apr 02 '18 at 21:47
  • 1
    Note: `mysql_*` functions are deprecated and removed in PHP7. – Syscall Apr 02 '18 at 21:48
  • Assuming this is caused by the variable name case typo, I voted to close as off-topic: typo. Please let me know if that's _not_ what was causing the problem and I'll retract the CV. – Don't Panic Apr 02 '18 at 21:51
  • if you just want a count, selecting everything and looping is not he way to go, `SELECT count(id) as total from skills` then just check the value for `total` in the result. –  Apr 02 '18 at 21:51

1 Answers1

2

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

PHP variables are case sensitive.