Jump to content

Returning a RecordSet in a table


seran128

Recommended Posts

I have two pages the first page has
index.php
[code]<?
include('functions.php'); 

$content = getcontent();

?>[/code]

then later in that page I want to <? echo $content ?> so i can place the results of the function anywhere on my page.


Functions.php

[code]function getcontent(){
global $connection;
$sql="select * from content";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
?>


<table width="200" border="1">
  <tr>
    <td><? echo stripslashes($row['content']); ?></td>
  </tr>
    <tr>
    <td>...................................................</td>
  </tr>
</table>


<?

}
return $news;
}[/code]

the problem is that it print the table out at the top of the page. I need to get the results of this function into a var named $news then I can echo that on the first page and controll  its placement
Link to comment
Share on other sites

you need to make $news equal the content. Then echo $content

[code]
while ($row = mysql_fetch_array($result)) {
  $news .= "<table width='200' border='1'>
    <tr>
      <td>" . stripslashes($row['content']) . "</td>
    </tr>
    <tr>
      <td>............................................</td>
    </tr>
  </table>";
}
return $news;
[/code]

then

[code]
echo ($content = getcontent());
[/code]
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.