Aureole Posted July 23, 2007 Share Posted July 23, 2007 I know, I know, I'm useless. $query = "SELECT title, url, content FROM modules WHERE id='1'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_row($result)) { $m_bungietitle = $row['title']; $m_bungieurl = $row['url']; $m_bungiecontent = $row['content']; } And then the code to display... <div class="rightcolumntitle"> <img src="img/rightcolumn_title_right.png" width="11px" height="27px" alt="." align="right" />Bungie Weekly Update </div> <div class="rightcontent"> <p class="newsinfo"> <a href="<?php echo "$m_bungieurl"; ?>" target="_blank" class="newstitle"><?php echo "$m_bungietitle"; ?></a><br /><?php echo "$m_bungiecontent"; ?> </p> </div> I'm not getting any errors and nothing is showing, yes I connect to the database already. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/ Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 Try... <?php $query = "SELECT title, url, content FROM modules WHERE id='1'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)) { while($row = mysql_fetch_row($result)) { $m_bungietitle = $row['title']; $m_bungieurl = $row['url']; $m_bungiecontent = $row['content']; } } else { echo "No records found"; } ?> PS: Variables do not need to be surrounded by quotes. <a href="<?php echo $m_bungieurl; ?>" target="_blank" class="newstitle"><?php echo $m_bungietitle; ?></a><br /><?php echo $m_bungiecontent; ?> Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305387 Share on other sites More sharing options...
AndyB Posted July 23, 2007 Share Posted July 23, 2007 'Nothing is showing' - do you mean an absolutely blank screen and when you use view>source to see the page html there's nothing visible? Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305393 Share on other sites More sharing options...
Aureole Posted July 23, 2007 Author Share Posted July 23, 2007 No I'll show you what I mean...go here and look on the right side underneath "Bungie Weekly Update". You will see nothing, but that's where the results should be and thanks thorpe but it still doesn't show anything and it doesn't show "No records found" or an error etc. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305399 Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 If none of the html is showing up, then you have other problems as well. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305421 Share on other sites More sharing options...
Aureole Posted July 23, 2007 Author Share Posted July 23, 2007 No the HTML is showing...the entire page is showing, except the part with the results... Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305425 Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 Where is your first part of code in relation to the second? Are you also aware that if you expect more than one result you will need to loop through all the html as well, and if your not, you don't need any loop at all? Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305429 Share on other sites More sharing options...
Aureole Posted July 23, 2007 Author Share Posted July 23, 2007 I only need one result it's my way of making content editable to other people without having to mess around with html, I just store the content in the database instead...and the query is near the top after the body and the code to display the things is near the bottom. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305432 Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 Well not your issue, but you dont need the loop then... <?php $query = "SELECT title, url, content FROM modules WHERE id='1'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)) { $row = mysql_fetch_row($result); $m_bungietitle = $row['title']; $m_bungieurl = $row['url']; $m_bungiecontent = $row['content']; } else { echo "No records found"; } ?> The only other thing I can suggest is make sure error reporting is on and ready for display. there is nothing inherently wrong with the code. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305437 Share on other sites More sharing options...
Aureole Posted July 23, 2007 Author Share Posted July 23, 2007 How do I make sure error reporting is on and I tried without the loop it doesn't work... Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305452 Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 and I tried without the loop it doesn't work... It doesn't work with it! If you only expect one result, you DONT need a loop. As for error reporting, place this at the top. <?php ini_set('error_reporting','1'); ini_set('display_errors','1'); ?> Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305457 Share on other sites More sharing options...
Aureole Posted July 23, 2007 Author Share Posted July 23, 2007 Ok I enabled error reporting and there are NO errors, what the... You said there wasn't anything really wrong with the code so why is this happening...it's just my luck. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305463 Share on other sites More sharing options...
Aureole Posted July 23, 2007 Author Share Posted July 23, 2007 Nobody have any ideas why I'm having problems? ??? Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305524 Share on other sites More sharing options...
trq Posted July 23, 2007 Share Posted July 23, 2007 If you trully are getting no errors and the variables defined after your query are remaining within scope then I don't see a problem. Maybe if you post your entire script. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305528 Share on other sites More sharing options...
AndyB Posted July 23, 2007 Share Posted July 23, 2007 Humour us. Create a brand new script that contains nothing more than this. Save it as test1.php, upload to your server and run it: <?php ini_set('error_reporting','1'); ini_set('display_errors','1'); // add your connection stuff and database selection stuff here $query = "SELECT title, url, content FROM modules WHERE id='1'"; $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result)) { while($row = mysql_fetch_row($result)) { $m_bungietitle = $row['title']; $m_bungieurl = $row['url']; $m_bungiecontent = $row['content']; ?> <a href="<?php echo $m_bungieurl; ?>" target="_blank" class="newstitle"><?php echo $m_bungietitle; ?></a><br /><?php echo $m_bungiecontent; ?> <?php } } else { echo "No records found"; } ?> Tell us the output and what view-source shows. Link to comment https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/#findComment-305529 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.