Jump to content

[SOLVED] mysql_fetch_assoc simply not retrieving any data from the columns


dazzclub

Recommended Posts

Hi people,

 

my code below doesnt seem to be retrieving any data. The data im calling or accessing is "headline", "date" and "publication"

 

<?php

$sql ="SELECT * FROM press_material ORDER BY id";

if($result = mysql_query($sql))

 

while($row = mysql_fetch_assoc($result)) {

 

 

 

echo '

<tr>

<td>' .$row['headline']. '</td>

<td>' .$row['date']. '</td>

<td><a href="press/' .$row['publication']. '.pdf" title="' .$row['publication']. '" target="_blank">' .$row['publication']. '.pdf </a></td>

</tr>';}

?>

 

any ideas to what i have forgotton to do?

 

regards

Dazzclub

double post in the same section, nice!  you could have at least tried another section...

 

Hmm, that looks correct, you sure there's something in press_material?  Change this line:

 

$result = mysql_query($sql) or die(mysql_error());

my guess is that when you throw on some error reporting you'll find msql screaming at you about using "date" as a column name.  If you want to use reserved words as column names, you need to wrap them up in backticks like so: `date` ... but you shouldn't do that because that only really works for mysql and also it's bad programming practice to use reserved words as column names.

 

but i could be wrong.  Not about the whole backtick thing; about the problem.

Hi people,

 

Firstly a huge apologies for breaking the forum rules, ive been here long enough and posted several topics that i should no better. Double posting was caused when i submitted my post, the process just seemed to just hang there. You know where the input box changes colour, like an overlay. so i just simply refresed and hence the double post.

 

No excuse for not wrapping my code, its very annoying for you guys, sorry.

 

The reason for my problem was caused by my host losing the database even though i double checked to see if any data was there it was.

 

Again sorry and thanks, I appreciate all your help.

 

Regards

Dazzclub

Just for info, DATE is not a reserved word.

 

my guess is that when you throw on some error reporting you'll find msql screaming at you about using "date" as a column name.  If you want to use reserved words as column names, you need to wrap them up in backticks like so: `date` ... but you shouldn't do that because that only really works for mysql and also it's bad programming practice to use reserved words as column names.

 

but i could be wrong.  Not about the whole backtick thing; about the problem.

For portability it's best avoided. MySQL is lenient regarding its use but I think it's better always to qualify it, such as

 

purchase_date

start_date

date_registered

 

instead of plain "date"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.