Results 1 to 4 of 4

Thread: Need PHP function

  1. #1
    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.

  2. #2
    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;


  3. #3
    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;


  4. #4
    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

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,280,975.30979 seconds with 17 queries