What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Whats wrong with this php code?

Pages: (2): « First [ 1 ] 2 » Last »
Whats wrong with this php code?
Author: Message:
Quantum
Disabled Account
*****

Away.

Posts: 1055
Reputation: -17
30 / Male / Flag
Joined: Feb 2007
O.P. Wink  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 :)
No longer here.
01-02-2008 06:34 PM
Profile PM Find Quote Report
saralk
Veteran Member
*****

Avatar

Posts: 2598
Reputation: 38
35 / Male / Flag
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
Profile PM Find Quote Report
Quantum
Disabled Account
*****

Away.

Posts: 1055
Reputation: -17
30 / Male / Flag
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]
No longer here.
01-02-2008 06:50 PM
Profile PM Find Quote Report
MeEtc
Patchou's look-alike
*****

Avatar
In the Shadow Gallery once again

Posts: 2200
Reputation: 60
38 / Male / Flag
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.
[Image: signature/]     [Image: sharing.png]
I cannot hear you. There is a banana in my ear.
01-02-2008 08:09 PM
Profile PM Web Find Quote Report
win_crook
Junior Member
**


Posts: 63
Reputation: 2
31 / Male / Flag
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 (Y)
01-02-2008 08:21 PM
Profile PM Find Quote Report
Quantum
Disabled Account
*****

Away.

Posts: 1055
Reputation: -17
30 / Male / Flag
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.
No longer here.
01-02-2008 09:11 PM
Profile PM Find Quote Report
win_crook
Junior Member
**


Posts: 63
Reputation: 2
31 / Male / Flag
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
Profile PM Find Quote Report
ShawnZ
Veteran Member
*****

Avatar

Posts: 3146
Reputation: 43
32 / Male / Flag
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
Profile PM Web Find Quote Report
Quantum
Disabled Account
*****

Away.

Posts: 1055
Reputation: -17
30 / Male / Flag
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.
No longer here.
01-02-2008 11:36 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
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.
[Image: 1-0.png]
             
01-02-2008 11:41 PM
Profile PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On