0

Ok so I've searched and searched but still struggling to resolve my problem. This is my current php coding:

$show = "Select effectiveness, round((Count(effectiveness)* 100 / (Select Count(*) From acupuncture))) as Score
From acupuncture
Group By effectiveness
ORDER BY Score DESC";
$result = mysql_query ($show);

WHILE($show = mysql_fetch_array($result))
{
$field1 = $show[effectiveness];
$field2 = $show[Score];

echo "$field1: ";
echo "$field2%<br><br>";
}

In addition to displaying the above I would also love to display the number of rows in the table. I know the sql code is:

"SELECT COUNT(id) AS entries FROM acupuncture"

Problem is when I try to input this into my php page I keep getting errors. I want to show both SELECT statement results on the one php page. If someone can help I would greatly appreciate it.

Thank you Shikz

All good, problem has been fixed. Thanks for all your help :) P.S. This is the code I inputted:

$size = @mysql_query("SELECT COUNT(*) AS `total` FROM acupuncture");
$query = mysql_fetch_array($size);
echo "Number of entries: ";
echo $query['total'];
echo "<br><br>";

I was writing up the php code incorrectly before, but now all good. Thanks again.

8
  • Show what you are doing and what errors you are getting. There's no reason that you couldn't execute multiple queries on the same "page". Commented Jan 29, 2013 at 9:35
  • What are you getting for errors? Commented Jan 29, 2013 at 9:36
  • You should really be using MySQLi or PDO by the way. Commented Jan 29, 2013 at 9:38
  • That uppercase WHILE is making me cringe. Commented Jan 29, 2013 at 9:40
  • Well, actually, not really getting errors, more, nothing is working :P I tried the following code, which is inputting data into my database, but nothing is being display on my php page... Commented Jan 29, 2013 at 11:57

2 Answers 2

1

Try this:

while($show = mysql_fetch_assoc($result))
{
  $field1 = $show['effectiveness'];
  $field2 = $show['Score'];

  echo "$field1: ";
  echo "$field2%<br/><br/>";
}

To cound all rows found read here

Small hints:

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

1 Comment

I've never even heard of PDO or mysqli. This is the first time I'm creating a website so yeah, lots to learn, yikes.
0

Make change in

WHILE($show = mysql_fetch_array($result))
{
   $field1 = $show[effectiveness];
   $field2 = $show[Score];

   echo "$field1: ";
   echo "$field2%<br><br>";
}

TO

WHILE($row= mysql_fetch_array($result))
{
   $field1 = $row[effectiveness];
   $field2 = $row[Score];

   echo "$field1: ";
   echo "$field2%<br><br>";
}

2 Comments

@Shikha , U have declared $show variable 2 time one for select query and another in while loop , so maybe because of this you getting errors.
Devang, thanks for the response. To be honest not quite sure what I'm doing, lol. Basically what I'm trying to do is out of a number of medical treatments find out what's the most effective with the help from the public and also display the number of people who have inputted their data on what treatment is more effective. My website is www.ibs-experiment.com ... It's still in beta mode. But yeah, learning everything for the first time. If you could suggest a better code structure I could use I would greatly appreciate that. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.