get rid of numeric key?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
winky3d
Forum Newbie
Posts: 9
Joined: Thu Apr 26, 2007 1:37 pm

get rid of numeric key?

Post by winky3d »

The Ninja Space Goat | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm retreiving results from mySQL using php4:

Code: Select all

while($row = $db->sql_fetchrow($result, MYSQL_ASSOC)) 
{ 
$results_array[$count] = $row; 
$count++; 
} 

Then putting the array in a session var: 
$_SESSION["xxx"] = $results_array; 

Then checking the key value for export to csv: 

foreach ($_SESSION["xxx"] as $r) { 
foreach ($r as $key => $value) { 
echo key=$key || value=$value ; 
}} 

/*
Snipped output: 
key=0 || value=9 
key=id || value=9*/
Question:
Why do I get the numeric key/value?
How can I stop it from appearing?

Thx.


The Ninja Space Goat | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Because mysql_fetch_array() has been used when you actually want mysql_fetch_assoc().

We'll need to see the code inside the sql_fetchrow() method.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What does

Code: Select all

get_class($db);
print?

@d11wtq
  1. currently it's neither mysql_fetch_array nor fetch_assoc but sql_fetchrow
  2. http://de2.php.net/mysql_fetch_array wrote:Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works),
winky3d
Forum Newbie
Posts: 9
Joined: Thu Apr 26, 2007 1:37 pm

Post by winky3d »

Thanks for the replies...

I got it working by moving to a mySQL 4 set of classes and fetchrow.
Post Reply