Jump to content


Photo

Multiple values from a database function [Solveded]


  • Please log in to reply
7 replies to this topic

#1 seran128

seran128
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 26 October 2006 - 04:04 PM

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

<?
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;
	}	
	
?>
on my page I have

listcontent.php
<?

 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>


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 04:12 PM

(altered code)

adminfunctions.php
<?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;
}	
?>

listcontent.php
<?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>


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..
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 seran128

seran128
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 26 October 2006 - 04:23 PM

my new code but still not working

adminfunctions.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;
}		
	
?>



listcontent.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:
&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>


#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 04:34 PM

are you sure your query is returning a result? are you getting an error message of some kind?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 seran128

seran128
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 26 October 2006 - 04:39 PM

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

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 04:45 PM

'description' and 'content' spelled right? man..idk, it looks legit...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 October 2006 - 04:49 PM

add this to your function:

global $connection;

<?
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;
}		
	
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 seran128

seran128
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 26 October 2006 - 04:55 PM

thats it thanks!!!!!!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users