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
https://forums.phpfreaks.com/topic/26845-returning-a-recordset-in-a-table/
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]

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.