seran128 Posted October 26, 2006 Share Posted October 26, 2006 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 havelistcontent.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] Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/ Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 (altered code)adminfunctions.php[code]<?phprequire("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.. Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114850 Share on other sites More sharing options...
seran128 Posted October 26, 2006 Author Share Posted October 26, 2006 my new code but still not workingadminfunctions.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: <? 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] Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114856 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 are you sure your query is returning a result? are you getting an error message of some kind? Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114862 Share on other sites More sharing options...
seran128 Posted October 26, 2006 Author Share Posted October 26, 2006 i did a echo $sql; in the function and I getselect * from webcontent_regions where regionId='31'When I cut and paste that query in navicat I do get a result Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114870 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 'description' and 'content' spelled right? man..idk, it looks legit... Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114873 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 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] Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114878 Share on other sites More sharing options...
seran128 Posted October 26, 2006 Author Share Posted October 26, 2006 thats it thanks!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/25195-multiple-values-from-a-database-function-solveded/#findComment-114883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.