Jump to content

Recommended Posts

This is my function: (works perfecly)

function news(){
$query = mysql_query("SELECT `post_subject`, post_text FROM `phpbb_posts` WHERE `forum_id` = 2 ORDER by `post_id` DESC LIMIT 2");

while ($fetch = mysql_fetch_assoc($query)) {
$article[] = $fetch;
}
$article[0]['post_subject']; 
$article[1]['post_subject']; 
$article[0]['post_text'];
$artcile[1]['post_text'];
}

 

Now it's not showing up in my html.

 

here what've done. I called news(); at  the beginning and I put the variables where I needed to into my html such as:

<h2><?php echo $article[0]['post_subject']; ?></h2>
		<?php echo smiley_text($article[0]['post_subject']); ?><br /><br />
		<a href="#">Message Footer information</a>
	</div>

 

No text is showing up when I execute it. Whats a similar way to do this correctly?

 

thanks

 

Are you sure your information is coming out of the database correctly? Your syntax looks like it has some problems with it. Try this:

 

$query = mysql_query("SELECT post_subject, post_text FROM phpbb_posts WHERE forum_id='2' ORDER by post_id DESC LIMIT 2");

It very well may execute it, but you need to return the array from the function, then use it where you like. eg;

 

<?php $article = news(); ?>
<h2><?php echo $article[0]['post_subject']; ?></h2>
<?php echo smiley_text($article[0]['post_subject']); ?><br /><br />
<a href="#">Message Footer information</a>
</div>

This is the error I get:

Fatal error: Cannot use string offset as an array in C:\WAMP\www\CodersDesk\index.php on line 47

 

not sure if this is exacly how you do the returns... but...

 

return $article[0]['post_subject']; 
return $article[1]['post_subject']; 
return $article[0]['post_text'];
return $artcile[1]['post_text'];

 

 

You can only return one thing from a function.

 

<?php

function news(){
  $query = mysql_query("SELECT `post_subject`, post_text FROM `phpbb_posts` WHERE `forum_id` = 2 ORDER by `post_id` DESC LIMIT 2");

  while ($fetch = mysql_fetch_assoc($query)) {
    $article[] = $fetch;
  }
  return $article;
}

?>

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.