Whats wrong with this php code? |
Author: |
Message: |
Quantum
Disabled Account
Away.
Posts: 1055 Reputation: -17
31 / /
Joined: Feb 2007
|
O.P. Whats wrong with this php code?
code: //Tags//
$query_tags = mysql_query("SELECT id, name FROM pp_tags GROUP BY name ORDER BY COUNT(id) DESC LIMIT 0,50");
while ($row_tag = mysql_fetch_array($query_tags)) {
$tags[] = $row_tag;
}
$smarty->assign('tag', $tags);
//tags end
Thanks for your help
|
|
01-02-2008 06:34 PM |
|
|
saralk
Veteran Member
Posts: 2598 Reputation: 38
35 / /
Joined: Feb 2003
|
RE: Whats wrong with this php code?
I can't really help without the error messages, and it's a while since I have used php, but I don't think you can copy an array like that. You would need some sort of counter.
for example
code: $i = 0;
while ($row_tag = mysql_fetch_array($query_tags)) {
$tags[$i] = $row_tag;
}
I can't remember if $row_tag is an array or not. But something along those lines.
The Artist Formerly Known As saralk
London · New York · Paris
Est. 1989
|
|
01-02-2008 06:46 PM |
|
|
Quantum
Disabled Account
Away.
Posts: 1055 Reputation: -17
31 / /
Joined: Feb 2007
|
O.P. RE: Whats wrong with this php code?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [FILE LOCATION]
|
|
01-02-2008 06:50 PM |
|
|
MeEtc
Patchou's look-alike
In the Shadow Gallery once again
Posts: 2200 Reputation: 60
38 / /
Joined: Nov 2004
Status: Away
|
RE: Whats wrong with this php code?
Try running the query in PMA. It will fail there. You are sorting by COUNT(id) when you are not declaring it in the SELECT clause. and COUNT(id) will be a constant number anyway.
This post was edited on 01-02-2008 at 08:14 PM by MeEtc.
I cannot hear you. There is a banana in my ear.
|
|
01-02-2008 08:09 PM |
|
|
win_crook
Junior Member
Posts: 63 Reputation: 2
31 / /
Joined: Apr 2007
|
RE: Whats wrong with this php code?
code: $query_tags = mysql_query("SELECT COUNT(id) AS count_id, name FROM pp_tags GROUP BY name ORDER BY count_id DESC LIMIT 0,50");
That should work for the query
Also that array copying code doesn't look right either like saralk was saying.
So try this:
code: $i = 0;
while ($row_tag = mysql_fetch_array($query_tags)) {
$tags[$i] = $row_tag;
$i++;
}
You need to overwrite your while loop with that second piece of code.
Good Luck
|
|
01-02-2008 08:21 PM |
|
|
Quantum
Disabled Account
Away.
Posts: 1055 Reputation: -17
31 / /
Joined: Feb 2007
|
O.P. RE: Whats wrong with this php code?
while ($row_tag = mysql_fetch_array($query_tags)) {
It says that, that line is the wrong code.
|
|
01-02-2008 09:11 PM |
|
|
win_crook
Junior Member
Posts: 63 Reputation: 2
31 / /
Joined: Apr 2007
|
RE: Whats wrong with this php code?
Yeah.. it's saying it can't get the results from the query because the query failed. So you need to find out what is wrong with the query. Did you try replacing it with that code I gave you?
Or you could try and see if mysql_error() returns anything.
|
|
01-02-2008 09:52 PM |
|
|
ShawnZ
Veteran Member
Posts: 3146 Reputation: 43
32 / /
Joined: Jan 2003
|
RE: Whats wrong with this php code?
quote: Originally posted by win_crook
Also that array copying code doesn't look right either like saralk was saying.
huh? what doesn't look right about it?
Spoiler: the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
the game.
|
|
01-02-2008 10:40 PM |
|
|
Quantum
Disabled Account
Away.
Posts: 1055 Reputation: -17
31 / /
Joined: Feb 2007
|
O.P. RE: Whats wrong with this php code?
$row = mysql_fetch_array($confresult);
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Ok whats wrong with this.
|
|
01-02-2008 11:36 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: Whats wrong with this php code?
Why are you ordering your results by the number of rows?
The order by should just be id of you want to order it by that column. Don't try to order it by a number that will likely not exist as a column
$query_tags = mysql_query("SELECT id, name FROM pp_tags GROUP BY name ORDER BY id DESC LIMIT 0,50");
This post was edited on 01-02-2008 at 11:42 PM by Ezra.
|
|
01-02-2008 11:41 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|