Page 1 of 1

get rid of numeric key?

Posted: Thu Apr 26, 2007 1:41 pm
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]

Posted: Thu Apr 26, 2007 2:11 pm
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.

Posted: Thu Apr 26, 2007 2:11 pm
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),

Posted: Thu Apr 26, 2007 2:52 pm
by winky3d
Thanks for the replies...

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