Reputation: 2898
I have a php script below that I am hoping would return all the values of a sql table. It does do this but also returns a number and value after each of the expected lines
$condition = "usernames = '$user' AND password = '$pass' ";
$result = mysql_query("SELECT * FROM userbase WHERE $condition") ;
$row = mysql_fetch_array($result) ;
foreach ($row as $k => $v) {
echo "$k / $v <br>";
};
?>
The results look like this
0 / Mick Lathrope
name / Mick Lathrope
1 / op
jobtitle / op
2 / 07998 783 989
phone / 07998 783 989
3 / mwl707
usernames / mwl707
4 / testpass
password / testpass
All the data is there that i need But why am I also getting a number list ?
Any help please ?
Upvotes: 0
Views: 105
Reputation: 1
According to this you have to specify the result type you want, otherwise you get both:
MYSQL_ASSOC
or MYSQL_NUM
,
Example:
while ($row = mysql_fetch_array($result, MYSQL_NUM)){...}
Upvotes: 0
Reputation: 441
Use
$row = mysql_fetch_array($result, MYSQL_ASSOC) ;
to index only by column name
Upvotes: 2
Reputation: 22817
drop mysql_*
for PDO or mysqli;
you want to use mysql_fetch_assoc
to get just keys and no number indexes.
Upvotes: 0
Reputation: 2291
because you have used mysql_fetch_array.
If you want only columns then use mysql-fetch-assoc
Upvotes: 0