Jump to content

Another MYSQL query problem...


Aureole

Recommended Posts

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.  :P

Link to comment
https://forums.phpfreaks.com/topic/61364-another-mysql-query-problem/
Share on other sites

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; ?>

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.

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.

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.

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.

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.