Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-09-2009
Members
 
Join Date: May 2009
Posts: 45
Need PHP function

I have recently learn PHP and i am trying to write a function which can return a row from selected query. For example i have a table named as Boards and it consist of following rows as Advertisers, Location, Clicks, Hits, DateStart, DateEnd and i am trying to use the following function

PHP Code:
$advertiser1 'ACM';

function 
submit($advertiser1)
{

$q "SELECT Advertiser1, location, Clicks, Hits, datestart, dateend FROM

Boards where Advertisers like '
$advertiser1'";

if(
$r=odbc_exec($sqlconnect$q))
while(
$row=odbc_fetch_row($r))
{

$Advertiser odbc_result($r,"Advertisers");
$location odbc_result($r,"location");
$Clicks odbc_result($r,"Clicks");
$Hitsodbc_result($r,"Hits");
$start odbc_result($r,"datestart");
$end odbc_result($r,"dateend");


}

With the following code i will be getting two rows. Now can anyone tell me which function i have write so that i will return 2 Rows identical to the Advertiser name. In short i need a function which returns me all the data for the specific advertiser name.
Reply With Quote
  #2  
Old 02-09-2009
Member
 
Join Date: Nov 2005
Posts: 403
Need PHP function

Instead of using individual result into a variable, i would suggest you to first read the all the row into an array and then store those array in a element which will contain all the returned rows. If you are not able to understand then you can check out the below code which will give you an idea what i am trying to say


PHP Code:
if($S1=odbc_exec($sqlconnect$q))
while (
odbc_fetch_row($rs)) {
for (
$y1 1$y1 <= odbc_num_fields($S1); $y1++)
$arr[$x][$y1] = odbc_result($S1,$y1);
$y1++;
}
return 
$arr;

Reply With Quote
  #3  
Old 02-09-2009
Member
 
Join Date: Jan 2009
Posts: 86
Need PHP function

In this case i would suggest you to use odbc_fetch_array() instead of odbc_fetch_row() because this function returns a row from a recordset as an associative array and/or a numeric array and at the same time it also returns TRUE and False value too. For example you can take the following code where $results will be a 2-dimension array with all the query result1, the first dimension being the result row, the 2nd dimension being the column name.

PHP Code:
$result1 = array();
while(
$row_1 odbc_fetch_array($r1))
{
   
$result1[] = $row_1;

Reply With Quote
  #4  
Old 02-09-2009
Member
 
Join Date: Dec 2008
Posts: 101
Need PHP function

You can also check out the below links for more information about PHP function, by using it you will come to know how does function works and how to declare it.

Functions in PHP
Date function in PHP
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Need PHP function"
Thread Thread Starter Forum Replies Last Post
c++ equivalent function to the c-function 'sprintf Dilbert Software Development 6 13-12-2011 04:03 PM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 07:52 PM
How does abstract function differs from virtual function? Maddox G Software Development 5 29-01-2010 11:32 AM
Function keys don't function under windows XP GunFighter Hardware Peripherals 3 08-04-2009 11:07 PM


All times are GMT +5.5. The time now is 02:09 PM.