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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.