Jump to content

Archived

This topic is now archived and is closed to further replies.

seran128

Multiple values from a database function [Solveded]

Recommended Posts

I am new to php. I have come over from the darkside ASP/.net. My question how would i return the values from function to another page. My function is;

adminfunctions.php

[code]<?
require("connection.php");

function geteditcontent($inTable,$inId){
$sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$regionId=$row['regionID'];
$description=$row['description'];
$content=$row['content'];

return;
}

?>[/code]on my page I have

listcontent.php
[code]<?

include("../include/adminfunctions.php");
$fa =$_POST["fa"];
$id=$_POST["ItemId"];

  geteditcontent("webcontent_regions","$id");
?>

<form name="example" id="example" method="post" action="../include/formsubmit.php?mode=content">
<input type="hidden" name="id" value="<? echo $id; ?>" />
  <div align="left">
  <table width="100%" border="0">
  <tr>
    <td colspan="2" class="ListTableHeader" ><div align="center"><strong>Update Content</strong></div></td>
  </tr>
    <tr>
    <td class="Results" >Region Id:<? echo $id ?> <div align="left"></div>
Region Description:<? echo $description ?> <div align="left"></div></td>
  </tr>
 
  <tr>
    <td>
<textarea id="textarea1" name="test1" style="height: 100%; width: 100%;"><? echo $content ?>
</textarea></td>
  </tr>
</table>

  <input type="submit" name="Submit" value="Save Content">
  <input type="button" name="btnCancel" value="Cancel" onclick="JavaScript:history.back()" >
  </div>
</form>[/code]

Share this post


Link to post
Share on other sites
(altered code)

adminfunctions.php
[code]
<?php
require("connection.php");

function geteditcontent($inTable,$inId){
$sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
  $info[] = $row;
}
return $info;
}
?>
[/code]

listcontent.php
[code]
<?php

include("../include/adminfunctions.php");
$fa =$_POST["fa"];
$id=$_POST["ItemId"];

  $info = geteditcontent("webcontent_regions","$id");
?>

<form name="example" id="example" method="post" action="../include/formsubmit.php?mode=content">
<input type="hidden" name="id" value="<? echo $id; ?>" />
  <div align="left">
  <table width="100%" border="0">
  <tr>
    <td colspan="2" class="ListTableHeader" ><div align="center"><strong>Update Content</strong></div></td>
  </tr>
    <tr>
    <td class="Results" >Region Id:<? echo $id ?> <div align="left"></div>
Region Description:<? echo $info[0]['description'] ?> <div align="left"></div></td>
  </tr>
 
  <tr>
    <td>
<textarea id="textarea1" name="test1" style="height: 100%; width: 100%;"><? echo $info[0]['content'] ?>
</textarea></td>
  </tr>
</table>

  <input type="submit" name="Submit" value="Save Content">
  <input type="button" name="btnCancel" value="Cancel" onclick="JavaScript:history.back()" >
  </div>
</form>[/code]


if you are expecting only one row returned, then you can change your function. remove the [] from $info (or just return $row instead of $info) and then in your form do $info['description'] instead of $info[0]['description'] etc..

Share this post


Link to post
Share on other sites
my new code but still not working

adminfunctions.php

[code]<?
require("connection.php");

function geteditcontent($inTable,$inId){
$sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$info[] = $row;
}
return $info;
}

?>[/code]



listcontent.php

[code]<?
include("../include/adminfunctions.php");
$fa =$_POST["fa"];
$id=$_POST["ItemId"];

$info = geteditcontent("webcontent_regions","$id");
?>


<form name="example" id="example" method="post" action="../include/formsubmit.php?mode=content">
<input type="hidden" name="id" value="<? echo $id; ?>" />
  <div align="left">
  <table width="100%" border="0">
  <tr>
    <td colspan="2" class="ListTableHeader" ><div align="center"><strong>Update Content</strong></div></td>
  </tr>
    <tr>
    <td class="Results" >Region Id:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<? echo $id ?> <div align="left"></div>
Region Description:&nbsp;&nbsp;&nbsp;&nbsp;<? echo $info[0]['description'] ?> <div align="left"></div></td>
  </tr>
 
  <tr>
    <td>
<textarea id="textarea1" name="test1" style="height: 100%; width: 100%;"><? echo $info[0]['content'] ?>
</textarea></td>
  </tr>
</table>

  <input type="submit" name="Submit" value="Save Content">
  <input type="button" name="btnCancel" value="Cancel" onclick="JavaScript:history.back()" >
  </div>
</form>[/code]

Share this post


Link to post
Share on other sites
i did a echo $sql; in the function and I get

select * from webcontent_regions where regionId='31'

When I cut and paste that query in navicat I do get a result

Share this post


Link to post
Share on other sites
add this to your function:

global $connection;

[code]
<?
require("connection.php");

function geteditcontent($inTable,$inId){
global $connection;
       
        $sql="select * from $inTable where regionId='$inId'";
$result=mysql_query($sql,$connection) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
$info[] = $row;
}
return $info;
}

?>
[/code]

Share this post


Link to post
Share on other sites

×

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.