anyone know PHP?

Jul 20, 2010 10:58

So I'm working on the tardis_bigbang website, and this year, in a fit of insanity, I decided that we really need to put it in a MySQL database. And things are going really well, except I'm being tripped up by something that should be completely simple.

[ETA: Figured it out. I should have known as soon as I'd post this, the light bulb would go on. I should have been using mysql_fetch_assoc instead of mysql_fetch_row]

Here's what the SQL stuff looks like:

$sql = "SELECT authorLJ, author_name from author_info";
$result = mysql_query($sql,$link) or die("Unable to select: ".mysql_error());
while($row = mysql_fetch_row($result)) {
...etc.

Now, if I print the results using

foreach($row as $field) {
print "$field";

...all 18 rows of the query print correctly, both fields. So the query is working.

But. I can't print using an array to save my life.

If I say print $row[1], it prints the author_name, which is the second field in the query. Print $row[2] is blank. And the frustrating thing is, print $row[authorLJ] and print $row[author_name] do nothing. I've tried every combination of single quotes, double quotes and curly brackets I can think of, and I'm absolutely stumped.

Can someone please, please tell me what I'm doing wrong? I'm using a reference book, and I've been browsing PHP websites, and I honestly can't figure this out.

Help, help, help, help, help.

Thanks!

computer, php

Previous post Next post
Up