Function with Return
Posted: Fri Apr 09, 2010 1:20 pm
Hello,
I am trying to put a function together to pull row fields from a database and not quite sure how to do it. Here is what I do have...
This is an include in my index.php page: function.php
This is the code that calls the function "Page". It passes along the ID of the page: index.php
This works fine and I can pull the page title. But what I am trying to do is return more than just a page title. The page consists of several database fields...
MetaTitle
PageTitle
Content
I am looking for a way to call the function and pull each field like so...
Or something similar. The main thing is to use the same function to pull all three fields separately. Any help in direction or samples would be much appreciated.
I am trying to put a function together to pull row fields from a database and not quite sure how to do it. Here is what I do have...
This is an include in my index.php page: function.php
Code: Select all
<?php
// Get Page by ID using echo Page('548');
function Page ($PageID) {
$colname_rsTest = "-1";
if (isset($PageID)) {
$colname_rsTest = $PageID;
}
mysql_select_db($database_conn, mysql_pconnect($hostname_conn,$username_conn,$password_conn));
$query_rsTest = sprintf("SELECT * FROM tblpages WHERE PageID = %s", GetSQLValueString($colname_rsTest, "int"));
$rsTest = mysql_query($query_rsTest, mysql_pconnect($hostname_conn,$username_conn,$password_conn)) or die(mysql_error());
$row_rsTest = mysql_fetch_assoc($rsTest);
$totalRows_rsTest = mysql_num_rows($rsTest);
return $PageTitle = $row_rsTest['PageTitle'];
mysql_free_result($rsTest);
}
?>Code: Select all
<?php echo Page($_GET['s']);?>This works fine and I can pull the page title. But what I am trying to do is return more than just a page title. The page consists of several database fields...
MetaTitle
PageTitle
Content
I am looking for a way to call the function and pull each field like so...
Code: Select all
<?php echo Page($_GET['s'], $PageTitle);?>
<?php echo Page($_GET['s'], $MetaTitle);?>
<?php echo Page($_GET['s'], $Content);?>