Re: var_dump() results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, January 14, 2008 12:21 pm, Europus wrote:
> Richard Lynch wrote:
>
>>> $link = mysql_pconnect('$host', '$login', '$passwd');
>>
>> '$host' is not right.
>>
>> $host is right.
>>
>> Ditto for ALL your values throughout this script.
>
> I know. I knew. I knew that variables do not need quotes, that
> single quoted variables get parsed literally. I edited the email
> to make those changes, the real values were contained in the
> actual script. See following (earlier than your reply?) emails.
>
> So blindfold me and shoot me for not taking the time to edit that
> bit of punctuation that was sent to the list, I asked for help on
> the loop and not help on connecting to the db. Oh, so shoot me for
> posting too much code, basically. I'm guilty as hell on that.
>
> In the actual test I tried after sending that email, probably I
> left a set of quotes in somewhere, I can't find any reserved word
> conflicts. Other replies indicate that it should work as intended,
> so probably I'll try it again.
>
>>> if (!$link) {
>>>      die('Unable to connect : ' . mysql_error());
>>
>> Forget the loop, this should have puked right here, or you aren't
>> posting your actual code...
>
> It was the actual code, edited for certain authentication data that
> is already identified elsewhere.
>
> phpinfo() says PHP v4.3.11 and MySQL v3.23.32 so why didn't it puke
> right there and why should it have?
>
> Please tell me, I need to learn more about these versions I must
> deal with too.

It should have puked because you couldn't have connected to a host
named '$host' is all.

>>> //get column data
>>> 	$sql    = "SELECT column2, column3 FROM $table";
>>> 	$result = mysql_query($sql);
>>> 	$row = mysql_fetch_row($result);
>>>
>>> //loop through to display results
>>> for($i=0; $i < count($row); $i++){
>>
>> The $row only has TWO columns in it: column2, column3
>
> Right. And?

And you are using count($row) which is always TWO (2) so you will
always show the same first row, twice over.

>> The $result may have many, many, many rows in it.
>> You can find out HOW many by using:
>> http://php.net/mysql_num_rows
>
> This has already been resolved, but I'd like to learn what I can
> from you re: your earlier comments, above.

Your take-home should not be that switching from mysql_fetch_row to
mysql_fetch_array somehow magically fixed it.

It should be that iterating over the result set with any mysql_fetch_*
function instead of iterating over the columns within a single row was
what you wanted to do.

A closer match of your original post would include:

$num_rows = mysql_num_rows($result); //Call function only once for loop:
for ($i = 0; $i < $num_rows; $i++){ //Iterate through all rows

> Aside, does everyone else think you are a butthead or are we off
> to a bad start? Let's fix that, can we?

If you want to take a poll and find out who thinks I'm a butthead,
feel free.

If you expect me to care if you think I'm a butthead or not, you're
out of luck.

:-) :-) :-)

You may want to look through the PHP-General archives for posts and
see if I appear to be a butthead in general, or if you just mistook my
ATTEMPT TO HELP YOU for being a butthead.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux