470,815 Members | 1,103 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

session registering a row from a mysql search

Bob
Hi,
I am having trouble registering a row from a mysql query

so far I have the mysql part working :

while ( $val = mysql_fetch_array( $result ))
{
print("<tr><td>$val[0]</td>
<td>$val[1]</td>
<td>$val[2]</td>
<td>$val[3]</td>
<td>$val[4]</td>
</tr>\n");
}

But, getting these fields into an array for which to register these is a bit
of a problem
any help would be appreciated, as soon as I do the fetch and priint them out
these fields seem lost to the world.

Thanks
Bob
Thanks
Jul 17 '05 #1
4 1764
I noticed that Message-ID: <zm********************@nasal.pacific.net.au>
from Bob contained the following:

while ( $val = mysql_fetch_array( $result ))
{
print("<tr><td>$val[0]</td>
<td>$val[1]</td>
<td>$val[2]</td>
<td>$val[3]</td>
<td>$val[4]</td>
</tr>\n");
}


try $val['fieldname']

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
Bob wrote:
I am having trouble registering a row from a mysql query
What do you mean with "registering"?
so far I have the mysql part working :

while ( $val = mysql_fetch_array( $result ))
{
print("<tr><td>$val[0]</td>
<td>$val[1]</td>
<td>$val[2]</td>
<td>$val[3]</td>
<td>$val[4]</td>
</tr>\n");
}
OK, this will print as many rows as the number of records returned from
the database.
But, getting these fields into an array for which to register these is a bit
of a problem
any help would be appreciated, as soon as I do the fetch and priint them out
these fields seem lost to the world.


Are you, by any chance, trying to access $val /outside/ the while loop?

<?php
while ($val = mysql_fetch_array($result)) {
print("...");
$valid_data_array = array($val[0], $val[1], $val[2]); // ok here
}
$invalid_data_array = array($val[0], $val[1], $val[2]); // wrong!
?>

You might want to increase the level of error_reporting in your scripts
to have php itself tell you about the use of uninitialized variables and
a few other mistakes in coding that it can catch.
Put these lines at the very beginning of your scripts

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', '1');
?>

HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #3
Bob

"Pedro Graca" <he****@hotpop.com> wrote in message
news:2g************@uni-berlin.de...
Bob wrote:
I am having trouble registering a row from a mysql query


What do you mean with "registering"?
so far I have the mysql part working :

while ( $val = mysql_fetch_array( $result ))
{
print("<tr><td>$val[0]</td>
<td>$val[1]</td>
<td>$val[2]</td>
<td>$val[3]</td>
<td>$val[4]</td>
</tr>\n");
}


OK, this will print as many rows as the number of records returned from
the database.
But, getting these fields into an array for which to register these is a bit of a problem
any help would be appreciated, as soon as I do the fetch and priint them out these fields seem lost to the world.


Are you, by any chance, trying to access $val /outside/ the while loop?

<?php
while ($val = mysql_fetch_array($result)) {
print("...");
$valid_data_array = array($val[0], $val[1], $val[2]); // ok here
}
$invalid_data_array = array($val[0], $val[1], $val[2]); // wrong!
?>

You might want to increase the level of error_reporting in your scripts
to have php itself tell you about the use of uninitialized variables and
a few other mistakes in coding that it can catch.
Put these lines at the very beginning of your scripts

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', '1');
?>


thanks for your reply

i got around it quite simply :
(hides head in shame)

print("<tr><td>$val[0]</td>
<td>$val[1]</td>
<td>$val[2]</td>
<td>$val[3]</td>
<td>$val[4]</td>
</tr>\n");
$prod_id = $val[0];
$prod_name = $val[1];
$price = $val[2];
$quantity = $val[3];
$stock = $val[4];

then registered the variables i assigned val[n] too.
total newbie me.
Jul 17 '05 #4
Bob

"Pedro Graca" <he****@hotpop.com> wrote in message
news:2g************@uni-berlin.de...
Bob wrote:
I am having trouble registering a row from a mysql query


What do you mean with "registering"?
so far I have the mysql part working :

while ( $val = mysql_fetch_array( $result ))
{
print("<tr><td>$val[0]</td>
<td>$val[1]</td>
<td>$val[2]</td>
<td>$val[3]</td>
<td>$val[4]</td>
</tr>\n");
}


OK, this will print as many rows as the number of records returned from
the database.
But, getting these fields into an array for which to register these is a bit of a problem
any help would be appreciated, as soon as I do the fetch and priint them out these fields seem lost to the world.


Are you, by any chance, trying to access $val /outside/ the while loop?

<?php
while ($val = mysql_fetch_array($result)) {
print("...");
$valid_data_array = array($val[0], $val[1], $val[2]); // ok here
}
$invalid_data_array = array($val[0], $val[1], $val[2]); // wrong!
?>


doh !
basic tenets of structured programming.
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Bob | last post: by
1 post views Thread by windandwaves | last post: by
1 post views Thread by windandwaves | last post: by
4 posts views Thread by Chris Stegeman | last post: by
14 posts views Thread by windandwaves | last post: by
4 posts views Thread by | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.