Forum Moderators: coopster
$numofrows = mysql_num_rows($query);
for($i = 0; $i < $numofrows; $i++)
{
$row = mysql_fetch_array($query);
$str = "".$row['SGID']."";
$str .= ",";
$value = substr_replace($str,"",-1);
echo $value;
}
Here is my exact code with the new while loop...
//Check if the user info validates the db
$query = mysql_query("SELECT * FROM `CustomerUserSG` WHERE `Username` = '$Username'");
$numofrows = mysql_num_rows($query);
while($row = mysql_fetch_array($query)
$rows[] = $row['SGID'];
$value = implode(',',$rows);
echo $value;
That should have been generating an error though - it didn't?
After you add the parenthesis, if you're still not getting anything:
Were you getting anything before you posted the first time?
Variable names are case sensitive in PHP - is $Username correct, with the capital letter? Is the field name in the table SGID, all caps?
Make these changes to make sure you can see what's going on:
//Check if the user info validates the db
$query = mysql_query("SELECT * FROM `CustomerUserSG` WHERE `Username` = '$Username'");
if(!$query) {
echo mysql_error();
exit;
} // EndIf error in query
$numofrows = mysql_num_rows($query);
if(!$numofrows) {
echo "Username is '$Username'<br>\n";
exit;
} // EndIf empty result
while($row = mysql_fetch_array($query)) {
if(!isset($row['SGID'])) {
echo "The row is looking like this:<br>\n";
print_r($row);
exit;
} // EndIf field isn't set
$rows[] = $row['SGID'];
} // EndWhile getting rows
$value = implode(',',$rows);
echo $value;