Jump to content

php/sql query


Wildthing

Recommended Posts

mysql> select rep_surname, AVG(booked) from appointments group by rep_surname;
+-------------+-------------+
| rep_surname | AVG(booked) |
+-------------+-------------+
| nick             |      1.0000 |
| john             |      1.0000 |
+-------------+-------------+
2 rows in set (0.00 sec)
 

But there are 3 rows all all, John has 1 more entry

 

Did I miss something ? I am not real good at this

Link to comment
Share on other sites

So far I have

 

$result = mysql_query("SELECT rep_surname, COUNT(*) as tot  FROM appointments  GROUP BY rep_surname  ORDER BY tot");
 

 

Need it to echo the rep_name with the least amounts of "1" in booked field

kind of stuck

Link to comment
Share on other sites

Doing my head in

lol

 

 

$result = mysql_query("SELECT rep_surname, COUNT(*) as tot  FROM appointments  GROUP BY rep_surname  order by ASC LIMIT 1");

echo $row['rep_surname'];
---------------------------------------------

 

error in apache log

PHP Notice:  Undefined variable: row in /home/wildthin/public_html/grabbs/test.html on line 10
 

Link to comment
Share on other sites

the error means that you didn't fetch the data from the result set.

 

before you can use php/mysql for your data, you must first learn how to use php/myqsl for any data. you need to read a basic php/mysql tutorial/book so that you understand the steps needed to form an sql query statement, run that query, check if the query executed without any errors, and then fetch any resultant data from that query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.