Stumped by no column values

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

Stumped by no column values

Post by Sniper007 »

Code: Select all

$sql = 'SELECT *
FROM Recipies
WHERE 1';
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
$RItemName = $rowї'ItemName'];
$ROutPutX = $rowї'OutPut'];
...
When I echo $ROutPutX; it puts out nothing. I get no error, and I have DOZENS of other columns in this table that display 100% perfect (including ItemName). I SWEAR that colum exists in my databse (at least, that's what MySQL-Front and phpMyAdmin both tell me). And I SWEAR that the whole colum has a default value of 1. Sometimes it's a value of 4, or 12... but in this querry it's acting like the column is filled with NOTHING.

Am I going insane? What am I doing wrong?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

first off

you should use mysql_fetch_array/ not fetch_assoc. fetch_array fetches strings in text/number form into a array, assoc just does numbers.

I dont like your where clause, where 1

Should be like: WHERE field_name=value

use mysql_error() in your querys

mysql_query($result) or die(mysql_error());

etc
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

tim you kinda got that twisted around.. fetch_assoc returns an associative array.. (named entries) .. it's fetch_row that returns only numbered (offset) arrays.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both.
I meant to say fetch_array returns numeric or an associative array.

fetch_assoc only returns associative array(s)

so it would be better off to use fetch_array, not that it matters all the time. depends on what values are stored

sorry for the confusion, if any
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

<back on topic>
Sniper, you might try adding a print_r($row) inside the while loop there, so make sure the names are right.. maybe it's a typo.. :)
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

Advice Taken, Results Posted

Post by Sniper007 »

The print_r($row) returns this (concerning the OutPut value):
...Bronze Dagger [1] => 1 [Output] => 1 [2] => Black Smith...
But when I do an echo RIGHT after that print_r command, it doesn't show ANY value for the output! I'm stumped. Here's my code now (with suggestions incorporated):

Code: Select all

$sql = 'SELECT *
FROM Recipies WHERE 1';
$result = mysql_query($sql) or die(mysql_error()); ;
while ($row = mysql_fetch_array($result))&#123;
print_r($row);
$RItemName = $row&#1111;'ItemName'];
$ROutPutX = $row&#1111;'OutPut'];
echo "<br>";
echo $ROutPutX;
Thanks guys.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

notice the case difference of what appears in $row and what you ask for at $ROutPutX?
Sniper007
Forum Newbie
Posts: 17
Joined: Tue May 11, 2004 8:43 pm

You're right!

Post by Sniper007 »

SON OF A B$#@&!
There it is, right infront of me.

:oops:

ALL HAIL FEYD AND TIM!!!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:D that's a very easy mistake... :) ;)
Post Reply