dazzclub Posted October 22, 2008 Share Posted October 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/ Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 Use mysql_error after your query. Make sure you have error reporting and displaying turned on. Post your DB structure. Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-671828 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 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()); Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-671829 Share on other sites More sharing options...
Barand Posted October 22, 2008 Share Posted October 22, 2008 any ideas to what i have forgotton to do? Dazzclub Yes, reading the forum rules, particularly regarding double-posting and code tags. Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672015 Share on other sites More sharing options...
.josh Posted October 22, 2008 Share Posted October 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672037 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 you need to wrap them up in backticks like so: `date` So that's what they're called... Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672047 Share on other sites More sharing options...
dazzclub Posted October 22, 2008 Author Share Posted October 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672101 Share on other sites More sharing options...
Maq Posted October 22, 2008 Share Posted October 22, 2008 You forgot one thing.... mark as solved Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672134 Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672205 Share on other sites More sharing options...
.josh Posted October 22, 2008 Share Posted October 22, 2008 hmm for some reason I thought it was. Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672313 Share on other sites More sharing options...
Barand Posted October 22, 2008 Share Posted October 22, 2008 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" Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672321 Share on other sites More sharing options...
dazzclub Posted October 23, 2008 Author Share Posted October 23, 2008 Cheers for that... ...I'll amend that date aswell to something more suitable to the data that goes in the column. Quote Link to comment https://forums.phpfreaks.com/topic/129591-solved-mysql_fetch_assoc-simply-not-retrieving-any-data-from-the-columns/#findComment-672584 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.