delphi123 Posted August 25, 2009 Share Posted August 25, 2009 Hi folks, On the code below it's all working great, except certain columns stored in the db return an error, eg: Notice: Undefined index: id in C:\wamp\www\news\index.php on line 23 The only wild guess I can make is that these appear to be related to integers and/or these columns not have collation set? Can anyone help me fix this? while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr><td valign='top'><a href='{$row['id']}'>{$row['title']}</a><br>" . "<span style='font-size:10px'>{$row['text']}</span></td>" . "<td valign='top'>{$row['status']}</td>" . "</tr>"; } Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/ Share on other sites More sharing options...
JonnoTheDev Posted August 25, 2009 Share Posted August 25, 2009 <?php while($row = mysql_fetch_assoc($result)) { echo "<tr>\n <td valign='top'><a href='".$row['id']."'>".$row['title']."</a><br /> <span style='font-size:10px'>".$row['text']."</span></td>\n <td valign='top'>".$row['status']."</td>\n </tr>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/#findComment-905884 Share on other sites More sharing options...
delphi123 Posted August 25, 2009 Author Share Posted August 25, 2009 hmm that still returns the same errors - the text fields come through fine but id and status cause the errors Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/#findComment-905891 Share on other sites More sharing options...
JonnoTheDev Posted August 25, 2009 Share Posted August 25, 2009 The record must contain no id value. You should switch off notice errors in your php ini error_reporting = E_ALL & ~E_NOTICE Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/#findComment-905895 Share on other sites More sharing options...
delphi123 Posted August 25, 2009 Author Share Posted August 25, 2009 that's what's strange - it definitely does - I'm viewing the values in phpmyadmin!? Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/#findComment-905903 Share on other sites More sharing options...
JonnoTheDev Posted August 25, 2009 Share Posted August 25, 2009 Use print_r() on $row to see the data while($row = mysql_fetch_assoc($result)) { print_r($row)."<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/#findComment-905906 Share on other sites More sharing options...
delphi123 Posted August 25, 2009 Author Share Posted August 25, 2009 :-[ :-[ :-[ :-[ :-[ :-[ Oh dear! How stupid am I, forgot that I'd made a specific field selection in my sql request in the include file (soit was only grabbing those specific columns, rather than *). All works lovely now and I'm no longer pulling my hair - but apologies for wasting your time with such a stupid mistake! Your debugging idea to dump the database records is a great one though and I'll be sure to use it in future! Thanks very much for your amazingly quick and patient help! Quote Link to comment https://forums.phpfreaks.com/topic/171798-solved-undefined-index-error-on-retrieving-certain-table-columns/#findComment-905911 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.