Re: [PHP] session_start problems with FireFox on Mac

2008-01-13 Thread Europus

Jochem Maas wrote:


?>


...
to avoid this in future never add the closing php bracket to the end of
the php file (unless you explicitly want to output something after the
code in question - which is almost never the case), it is not required.

e.g.
- >8 info.php 
8 info.php 


I didn't know that. Does the underlying engine in PHP provide the
otherwise missing tag? Does the described problem only happen with
FF on Mac or does it affect other browsers on other OSes?

Ulex

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



Re: [PHP] session_start problems with FireFox on Mac

2008-01-13 Thread Europus

 Jochem Maas wrote:


you also mentioned you changed the code when trying to test it on another
machine - don't do that, test one thing at a time.


I'm not the original poster, that wasn't me.

anyway problem solved, preventative knowledge aquired, onto the next 
hurdle :-)


I'm having some trouble with a for() loop and echoing array results
to screen to see if I'm getting the data I'm after, I may post about
it later.

Ulex

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



[PHP] var_dump() results

2008-01-13 Thread Europus

It's pretty much the same. With var_dump(), values from the first row
of the table are iterated twice, the script is not looping through and
reporting all 2100 rows. Grossly similar behavior was observed with
print_r() and echo: while different data was reported by each, the
loop wouldn't loop. The first row was reported once (or twice) and
that was the end of that. I've tried foreach() also, same-same. It
doesn't loop, it just reports the first row.

Here's my code:

";
?>

Ulex

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



Re: [PHP] var_dump() results

2008-01-13 Thread Europus

T.Lensselink wrote:


Can you show some code?


Apparently I sent replies to T.Lensselink only, here's the meat of
the 2nd one:

--

Actually, it doesn't exactly iterate the 1st row 4 times, it's a bit
more convoluted.

The table fas 4 columns (Fields):
1 - int, primary, auto-incrementer
2 - varchar() values
3 - varchar() values
4 - varchar() values

and 2100 rows. I'm after the data in the 2nd and 3rd columns. The
return is 4 rows of this:

array(4) {
[0]=>  string(11) "col_2_row_1_data" ["col_2"]=>  string(11) 
"col_2_row_1_data"
[1]=>  string(13) "col_3_row_1_data" ["col_3"]=>  string(13) 
"col_3_row_1_data" }


This is way beyond my ken, but I want to learn so I'll keep plugging
at it. Tips & suggestions are welcome

Ulex

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



Re: [PHP] var_dump() results

2008-01-13 Thread Europus

Jochem Maas wrote:


side note: where does $table come from?


I didn't want to reveal the real names of my server/host, table,
login or password to the list, so I tried setting $host, $login,
$passwd, and $table variables at the top of the script. That way
it's 4 lines to omit when posting code, instead of parsing through
to edit each instance. That didn't work so I've since restored the
initial values, probably I stepped on a reserved word. I'll check
on that, I like the idea of setting those to variables elsewhere.


//get column data
$sql= "SELECT column2, column3 FROM $table";
$result = mysql_query($sql);


if (!$result) {
echo "query failed.\n";
} else {
while ($row = mysql_fetch_array($result))
var_dump($row);
}   




$row = mysql_fetch_row($result);


Now that, that change makes what looks to be 2100 rows of data flood
the screen, thank you. Now I can move on to processing that data
in the next step of my script.

It looks like, my take-away lesson is that I was invoking var_dump()
too late, I should have been performing that check right after running
mysql_fetch_array(), because later operations step on the data and
that's why I was getting unexpected returns.

Ulex

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



Re: [PHP] var_dump() results

2008-01-13 Thread Europus

Steve Edberg wrote:

As far as displaying only the first row, that's because you're only 
fetching the first row; count($row) in your for loop will always 
evaluate to 0 (if there are no results) or 1. You need to move the 
mysql_fetch_row() call into your loop; something like


$result = mysql_query($sql);
while ($row = mysql_fetch_row($result)) {
var_dump($row);
...
}

or you could do

$result = mysql_query($sql);
$count = mysql_num_rows($result);
for ($i=0; $i<$count; $i++) {
var_dump($row);
...
}


Noted, thank you. I'll play with these too, to see what I think of them.

As far as displaying the results twice, I'm not sure; that resembles the 
behavior of mysql_fetch_array() -


The script had ~fetch_array() initially, I couldn't get it to work as
expected so I changed it to ~fetch_row(). Now it's back to ~fetch_array()

Both as a learning exercise and as an end-goal, I'm rewriting some
code so that it does what I want it to, not what it imperfectly does
according to the original programmers intent. That original intent
bears only passing resemblance to what was requested of that programmer,
it's become a sore subject.


http://us.php.net/manual/en/function.mysql-fetch-array.php

- where the default is to return data as both an associative and 
numerically-indexed array. 


That explains some things. And I have some reading and experimenting
to do before I move on to the next step in the script.

I'm guessing that the above code isn't an 
exact cut-and-paste, as using single quotes (eg, mysql_pconnect('$host', 
'$login', '$passwd') does not interpolate variables, so that line will 
not work unless your username is actually '$login', etc. Which it 
probably isn't. 


Correct. That was my attempt to obfuscate some of my real data, the
username and password especially. See my other post on this.

Ulex

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



Re: [PHP] var_dump() results

2008-01-14 Thread Europus

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.


//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?


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.

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

Ulex

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



Re: [PHP] var_dump() results

2008-01-14 Thread Europus

Jochem Maas wrote:

there is no 'we' in 'you'. 


There's no "Jochem" in there either. No offense taken, btw.


Richard's posted more answers to more
posts on this list than you have written line of code in your life

...probably.


And yet. No, I'm not going to say what happened elsewhere, to you. It
would disrespect Lynch and me, both. I offered an olive branch, albeit
a very small one. Probably, Richard doesn't even realize the slight he
made and why I retorted. Certainly, he doesn't need you or anyone
else to swat it away before he's seen it and had a chance to decide
for himself.

Except for my forthcoming reply to Richard, this is my last reply on
this sub-topic to anyone who isn't Richard. As has been pointed out,
admitted to by me before it was pointed out, I have lots of reading
to do. I thought I was at the point where I should begin my transition
from the written word to the typed script. Well, maybe I'm a little
slow but I'm certainly not going to give up just because you think
you need to defend someone else. Contemplate your own zen garden, I
have work to do.

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



Re: [PHP] var_dump() results

2008-01-14 Thread Europus

Richard Lynch wrote:


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 wasn't. I thought it was that I was invoking var_dump(), print_r()
and "echo" at the wrong point to see what the output was. Also that
"echo" was an improper command to invoke.


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.


Well said, the point is driven home.


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


No bet, I couldn't resist yanking on your chain a little is all.


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

:-) :-) :-)


If you expect my feelings to be hurt as a result, you're in a
similar situation. :)


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.


Nope, that's not why. I mistook you for a butthead for your complete
failure to reply to other things, as backdrop for the presumptive tone
you took while addressing matters you would know had been resolved
already had you read through.

But maybe that's my fault. I appreciate the value you added to my
take-home lesson. Really and sincerely, I do. Looping over the
columns instead of the rows? That was stupid of me, your post
helped me see that error, thank you. You could have limited your
reply to that and we'd be two posts forward from where we are now.

Ulex

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