Germaris Posted October 20, 2006 Share Posted October 20, 2006 Hi there!This is a query of a PHP script I wrote which is supposed to return the number of rows for each different object present in the field nammed "list"[code=php:0]$query="SELECT list, count( * ) AS n FROM $table GROUP BY list HAVING ( n > 1 )";//I don't know how to write the followingprint (// ? ? ? ? ? );[/code]The result returned by this query is, FOR EXAMPLE, something like this list n_____________ai 72bg 325he 127etc...I want to send this result to my Flash file &ai=72&bg=325&he=127etc...but I don't know to write it the right way !!!Many thanks in advance for your help ! Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/ Share on other sites More sharing options...
Barand Posted October 20, 2006 Share Posted October 20, 2006 [code]<?php$query="SELECT list, count(*) AS n FROM $table GROUP BY list HAVING ( n > 1 )";$res = mysql_query($query);while (list($list, $n) = mysql_fetch_row($res)) { echo "$list : $n <br>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112063 Share on other sites More sharing options...
Germaris Posted October 20, 2006 Author Share Posted October 20, 2006 Thank you very much for your reply.I just gave it a try and... alas! It didn't work...Is "list" a reserved keyword (as it appears in green in your code, I suppose so...)?Anyway, thanks for your time!Regards. Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112074 Share on other sites More sharing options...
Barand Posted October 20, 2006 Share Posted October 20, 2006 Change the second line to$res = mysql_query($query) or die(mysql_error());and see if you get an error message Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112096 Share on other sites More sharing options...
Germaris Posted October 21, 2006 Author Share Posted October 21, 2006 [quote author=Barand link=topic=112165.msg455210#msg455210 date=1161381167]Change the second line to$res = mysql_query($query) or die(mysql_error());and see if you get an error message[/quote]Thanks for your time and your advice but I already did it and the query is good : I got no error at all and I got the expected result as I described it in my first post.You can yourself try it in one of your DB tables (replacing, of course the names of the fields! he he he) if you have one and using the window in the SQL Tab of phpMyAdmin...But would you please answer my question : Is "list" a reserved keyword in SQL Language ? Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112237 Share on other sites More sharing options...
Barand Posted October 21, 2006 Share Posted October 21, 2006 "LIST" is not in the list of MySQL reserved words.http://dev.mysql.com/doc/refman/4.1/en/reserved-words.htmlIt is a PHP function http://www.php.net/listI ran this[code]<?phpinclude 'db2.php'; // coonnection stuffmysql_query ("CREATE TABLE test1 ( id int not null auto_increment primary key, list varchar(5) )");mysql_query ("INSERT INTO test1 (list) VALUES ('aaaaa'), ('aaaaa'), ('aaaaa'), ('bbbbb'), ('aaaaa'), ('bbbbb'), ('ccccc'), ('aaaaa') ");$table = 'test1'; $query="SELECT list, count(*) AS n FROM $table GROUP BY list HAVING ( n > 1 )";$res = mysql_query($query) or die (mysql_error());while (list($list, $n) = mysql_fetch_row($res)) { echo "$list : $n <br>";}?>[/code]and got[pre]aaaaa : 5 bbbbb : 2 [/pre] Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112245 Share on other sites More sharing options...
Germaris Posted October 21, 2006 Author Share Posted October 21, 2006 The results you got do not surprise me as we are sure the query is good...We make some progress:I now get all the 45 fields of my Flash File populated (until now they stayed blank!).But I don't get any number in them: they all display "undefined" !!!!!Why the hell they do not receive the variables the query found?Have you some knowledge about Flash Action Script?I think it will help us to communicate...You are a very kind person to provide me with such help.Thank you!PS: Thanks also for the links about "list" and the SQL Reserved Keywords ! Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112250 Share on other sites More sharing options...
Barand Posted October 21, 2006 Share Posted October 21, 2006 [quote author=Germaris link=topic=112165.msg455368#msg455368 date=1161427629]Have you some knowledge about Flash Action Script?I think it will help us to communicate...[/quote]Unfortunately - noneNow you can get the variable names and values out of your database it may be better to go to a dedicated Actionscript forum to find out how to set the values inside Flash.Or maybe open a new topic here with title "Setting actionscript variables from PHP" which should attract the attention of those with PHP/actionscript knowledge.PS Does this helphttp://www.phpfreaks.com/forums/index.php/topic,96743.msg387573.html#msg387573 Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112254 Share on other sites More sharing options...
Germaris Posted October 21, 2006 Author Share Posted October 21, 2006 Thanks for your valuable help and for your advices!I've posted a New Topic "Setting ActionScript variables from PHP" in this forum.Hope some Flash geek will read it...How old are you("senile")? I'm 65!A+Gerard Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112275 Share on other sites More sharing options...
Barand Posted October 21, 2006 Share Posted October 21, 2006 57 Link to comment https://forums.phpfreaks.com/topic/24586-how-to-write-it/#findComment-112300 Share on other sites More sharing options...
Recommended Posts