0
<?php
$sqls = mysql_query("SELECT weight FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);
$ct = mysql_query ("COUNT * '$sqls'");

if ($ct > 0) {
   while ($row = mysql_fetch_array($sqls));{
      $weight = $row["weight"];
      echo "C" . $weight;
    }}
else {
  echo "No stats found";
}
?>

This outputs "No stats found" even though I have data in the table.

<?php
$sqls = mysql_query("SELECT weight FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);
$ct = mysql_num_rows($sqls);

if ($ct > 0) {
   while ($row = mysql_fetch_array($sqls));{
      $weight = $row["weight"];
      echo "C" . $weight;
    }}
else {
  echo "No stats found";
}
?>

This returns nothing. No echo at all.

I have checked to see if it is accessing by just using:

<?php
   $sqls = mysql_query("SELECT weight FROM $usertablestats")
   or die ("Query failed: " . mysql_error() . " Actual query: " . $query);

   $row = mysql_fetch_array($sqls);

   echo $row;
?>

And it does return the first entry.

4 Answers 4

1

You have semicolon in while :

while ($row = mysql_fetch_array($sqls));{
//should be
while ($row = mysql_fetch_array($sqls)){

Is that causing problem

Sign up to request clarification or add additional context in comments.

1 Comment

//Thank you! I am new at this, and I knew it had to be something really stupid on my part. It worked great. I don't suppose there is a way to subtract the last row from the first?
0

Try this:

<?php
$sqls = mysql_query("SELECT weight FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);

int $ct = 0;
while ($row = mysql_fetch_array($sqls)){
    $weight = $row["weight"];
    echo "C" . $weight;
    $ct++;
}

if ($ct == 0) {
    echo "No stats found";
}

?>

If it doesn't work then make sure that $usertablestats has the right value.

Comments

0

Try this.

while ($row = mysql_fetch_array($sqls,MYSQL_ASSOC)){
    $weight = $row["weight"];
    echo "C" . $weight;
    $ct++;
}

 

Comments

0
<?php
$sqls = mysql_query("SELECT * FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);

if (mysql_num_rows($sqls)!=0) {
   while ($row = mysql_fetch_assoc($sqls)){
   $weight = $row["weight"];
   echo "C" . $weight;
}}
else {
   echo "No stats found";
}
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.