PDA

Click to See Complete Forum and Search --> : [RESOLVED] Fetch, woof!


RobDog888
Oct 14th, 2007, 04:27 PM
Is there anything for when you are retrieving a single record from a db that you can read without having to use the fetch_array? Its only a single record/field so I would assume its still an array.

Do I really have to use ...

while ($r = fetch_array($rs))
{
$blah = $r['SomeBlahRelatedField'];
}

dclamp
Oct 14th, 2007, 04:35 PM
you dont have to use the while loop:


$res = mysql_fetch_array($query);
echo $res['whatever'];


also, you can just select a single field from the db:

"SELECT `whatever` FROM `mytable`"

RobDog888
Oct 14th, 2007, 05:05 PM
Yes, I am selecting a single field already as I mentioned which seems to reason that if I had a single record returned (db table primary key disallows dups) that I shouldnt have to use a while loop but is there any simple way to just read the field without the fetch_array is really more the question here.

Would I be able to do a ...
$blah = $rs['SomeBlahRelatedField'];

without using fetch_array? Any other functions like a fetch_item or fetch_record?

penagate
Oct 14th, 2007, 05:11 PM
But that's all fetch_array does: it returns one record.

RobDog888
Oct 14th, 2007, 05:27 PM
Ok thats true but is it really needed if you already have the resultset in the $rs var?

since that will hold the record could you do like I posted above? Oops it should be $rs and not $r.

penagate
Oct 14th, 2007, 05:32 PM
No .

RobDog888
Oct 14th, 2007, 05:42 PM
Why not?

dclamp
Oct 14th, 2007, 06:20 PM
because, we said so. lol

I dont think there is a specific reason. It doesn't really make a big impact since you are only pulling 1 column anyway.

RobDog888
Oct 14th, 2007, 06:28 PM
Umm, phpclamp, when you look at the big picture you will see things differently. One "extra" call by itself is no issue but when you add all the calls on the page it can really bog down a page's loading time. ;)