Jump to content

Recommended Posts

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 following
print (
// ? ? ? ? ?
);
[/code]

The result returned by this query is, FOR EXAMPLE, something like this

list    n
_____________
ai      72
bg      325
he      127
etc...

I want to send this result to my Flash file

&ai=72
&bg=325
&he=127
etc...

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

[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

"LIST" is not in the list of MySQL reserved words.

http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html

It is a PHP function

http://www.php.net/list


I ran this
[code]
<?php
include 'db2.php'; // coonnection stuff

mysql_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

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

[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  - none

Now 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 help
http://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

Guest
This topic is now closed to further replies.
×
×
  • 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.