Page 1 of 2
REALLY weird db problem
Posted: Fri Nov 25, 2005 5:22 pm
by JasonTC
I have a database with a table called
email_addresses. This table has only one column:
email. There are only two records in the table.
I'm performing the following statements:
Code: Select all
global $db_connection;
$sql = "SELECT email FROM email_addresses;";
$result = odbc_exec($db_connection, $sql);
// send a message to each e-mail address in the table
while ($row = odbc_fetch_row($result))
{
$email = $row['email'];
echo "mail to: <b>\$email</b>: $email<br>"; // for debugging purposes
send_message($email, $subject, $message); // special function I wrote
}
There's more to my script but I don't think it should really matter. The output of my script is:
Obviously, $row = odbc_fetch_row($result) is evaluated as true exactly twice, which is the number of records in my table. The weird thing is that no records are being displayed - I've double and triple-checked the name of the column "email", too. What's the deal?
Thanks,
Jason
Posted: Fri Nov 25, 2005 5:42 pm
by Charles256
note: this could be me being special..
did you mean fetch_row as opposed to fetch_row
??
Posted: Fri Nov 25, 2005 5:49 pm
by JasonTC
did you mean fetch_row as opposed to fetch_row
Is that what you meant to put? ("fetch_row" = "fetch_row")
Posted: Fri Nov 25, 2005 5:53 pm
by Charles256
LMAO, i meant fetch_array instead of fetch_row. my mistake.
Posted: Fri Nov 25, 2005 5:57 pm
by JasonTC
fetch_array yields no results whatsoever. Check out this weird and possibly related problem:
viewtopic.php?t=41230
Posted: Fri Nov 25, 2005 5:58 pm
by Charles256
any chance of you using mysql?:-D
edit: or try using fetch_object and then change $row['email'] to $row->email
Posted: Fri Nov 25, 2005 6:09 pm
by JasonTC
Not mysql, just regular or whatever. Microsoft Server, Access database.
fetch_object with $row->email also yielded no results.
Posted: Fri Nov 25, 2005 6:31 pm
by Charles256
and there is information in the database for it to be pulling out??? :: scratching his chin::
Posted: Fri Nov 25, 2005 6:47 pm
by JasonTC
I'm gonna end this here and post a new thing on the database forum.
Posted: Fri Nov 25, 2005 6:49 pm
by trukfixer
Code: Select all
//add after the $result query:+
echo mysql_error();
echo"<pre>";
var_dump($result);
//add after the while($row.. stuff
var_dump($row);
see what happens

Posted: Fri Nov 25, 2005 7:02 pm
by JasonTC
All right, well that gives me something, at least:
But what does
that mean?
Posted: Fri Nov 25, 2005 9:36 pm
by trukfixer
JasonTC wrote:All right, well that gives me something, at least:
But what does
that mean?
OK so that means your database connection worked, and you have a result set from the db query -
what happens when you do the var_dump($row) ?
Code: Select all
while ($row = odbc_fetch_row($result))
{
echo "<pre>";
var_dump($row);
.... your code continues...
if that gives you no data (not *EVEN* a NULL or array(0)) , that would mean your while() loop never executes
**** Ohhhh DUH.. on me . I didnt even NOTICE ***
I was about to say that you would want to look closely at your while() loop, so I did, and finally realized:
mysql_fetch_row() fetches a *SINGLE* row
you want either mysql_fetch_array($result) or mysql_fetch_assoc($result)
try either of those with the var_dump($row); stuff above and see what happens (or try all three fetch methods)
Posted: Fri Nov 25, 2005 9:42 pm
by Roja
JasonTC wrote:I'm gonna end this here and post a new thing on the database forum.
No need. Moved!
Posted: Fri Nov 25, 2005 10:37 pm
by RobertGonzalez
JasonTC wrote:Code: Select all
// send a message to each e-mail address in the table
while ($row = odbc_fetch_row($result))
{
$email = $row['email'];
echo "mail to: <b>\$email</b>: $email<br>"; // for debugging purposes
send_message($email, $subject, $message); // special function I wrote
}
Have you tried removing the "" from in front of the "$email". I think if you escape the dollar sign the var will be treated as literal (or at least the dollar sign would be escaped rendering it as an actual "$" instead of your variable.
Just my $0.02.
Posted: Fri Nov 25, 2005 10:42 pm
by Charles256
the first time u see $email he is just setting up to output the variable email is "insert e-mail"
or literally $email : "insert e-mail"