Page 1 of 1
Stumped by no column values
Posted: Thu May 20, 2004 10:53 pm
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?
Posted: Thu May 20, 2004 11:02 pm
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
Posted: Thu May 20, 2004 11:19 pm
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.
Posted: Thu May 20, 2004 11:23 pm
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
Posted: Thu May 20, 2004 11:34 pm
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..

Advice Taken, Results Posted
Posted: Fri May 21, 2004 2:59 pm
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)){
print_r($row);
$RItemName = $rowї'ItemName'];
$ROutPutX = $rowї'OutPut'];
echo "<br>";
echo $ROutPutX;
Thanks guys.
Posted: Fri May 21, 2004 3:05 pm
by feyd
notice the case difference of what appears in $row and what you ask for at $ROutPutX?
You're right!
Posted: Fri May 21, 2004 4:58 pm
by Sniper007
SON OF A B$#@&!
There it is, right infront of me.
ALL HAIL FEYD AND TIM!!!
Posted: Fri May 21, 2004 6:34 pm
by feyd

that's a
very easy mistake...
