Reputation: 1566
Can someone please explain why this code is not outputting a value for $consultant
When the data base is as follows:
And below is the code...
<?php include ("include/config.php");
$SUC = mysql_query("
SELECT `decisionValue` FROM `teamdecision` WHERE `decisionType` = 'SUconsultant'
")or die($SUC."<br/><br/>".mysql_error());
$SUNumR = mysql_num_rows($SUC);
$consultant = array();
$i="0";
while ($i<$SUNumR && $row = mysql_fetch_assoc($SUC))
{
$consultant[$i] = $row['SUconsultant'];
echo $consultant[$i];
$i++;
}
?>
Thanks
Upvotes: 1
Views: 102
Reputation: 944
In addition to other answers, The $i
counter in your script is completely unnecessary. Here's a much simpler approach:
<?php
include('include/config.php');
$SUC = mysql_query("SELECT decisionValue FROM teamdecision WHERE decisionType = 'SUconsultant'") or die(mysql_error());
$consultant = array();
while ($row = mysql_fetch_assoc($SUC))
{
echo $consultant[] = $row['decisionValue'];
}
?>
Upvotes: 3
Reputation: 7310
You are only selecting decisionValue
in your SQL query, change it to:
SELECT `decisionValue`, `SUconsultant` FROM `teamdecision` WHERE `decisionType` = 'SUconsultant'
Upvotes: 0
Reputation: 526573
You're not selecting SUconsultant
as one of your columns, so why are you expecting it to be in the result row?
SELECT `decisionValue` FROM `teamdecision`
Whatever key you're referencing in your result set, you should select it as well.
Upvotes: 2