GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Dec-2003, 09:07
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about

Using datafeeds for affiliate programs


One of my recent sites focuses a complete section catered by one merchant and this has led me to start work on integrating their datafeed into the web site.

Is anyone out there using datafeeds? I haven't had much luck finding any articles or posts on this and I will most likely start this project from scratch using PHP/MySql.

Any tips or ideas?
__________________
Web Hosting Tips | Career Advice
  #2  
Old 01-Dec-2003, 09:17
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
The last time I communicated with a merchant / advertiser about their datafeed, he pointed me to this one humungous text file - that put a damper on my (very) brief foray into this idea.

This datafeed you talk about, is it in XML or simply a text file or something else?
  #3  
Old 01-Dec-2003, 10:53
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about
The one I looked at was a tab delimitted text file...about 600k. It would be a manual process but the changes are usually minor.
__________________
Web Hosting Tips | Career Advice
  #4  
Old 01-Dec-2003, 22:48
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Import the text file into MySQL


The next question is: Do you see yourself using the datafeed off the text file directly or would you prefer to import this datafeed into a database table for instance?

If it were up to me, I would go the way of importing it into a MySQL database table - for obvious reasons (one of them being SPEED).

If this is what you would prefer to do too, then you'd have to share the following information so I can suggest a few things:
  • Do you have MySQL installed in your PC and in the (remote) web server?
  • What MySQL version for each? Preferably, they should be the same version.
  • You have to ask your web host if you have permission to run a query like this? LOAD DATA INFILE "xyz_datafeed.txt" INTO TABLE `xyz_table`. But it's not totally necessary...
  • Can you post the first few lines off your datafeed / text file so we have some kind of idea how we will create the MySQL table.
  #5  
Old 02-Dec-2003, 11:38
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about
Yeah I was thinking that putting it into a MySQL database would be the best way to go. Here are the fields I'll be dealing with.

Quote:
Product_Name Keywords Description Code Buy_URL Small_Images Large_Images Price Stock_Status Organization Team_Name Team_Short_Name Product_Type Prod_Type_Subcat

I don't think it'll be too bad...should find out when I start tonight.
__________________
Web Hosting Tips | Career Advice
  #6  
Old 03-Dec-2003, 13:46
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about
Alright,

So I decided to do most of the database stuff through PHPMyadmin and so far so good. Created the table and inserted all the data...now to the next step, running some queries.
__________________
Web Hosting Tips | Career Advice
  #7  
Old 03-Dec-2003, 15:37
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about
Thumbs up

Almost done...just have to work on the formatting the output.
__________________
Web Hosting Tips | Career Advice
  #8  
Old 03-Dec-2003, 17:29
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about
A few hiccups. Here my partial code for the output:

PHP Code:

while ($row = mysql_fetch_array($result))
{

echo "
<table width='500' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='250' valign='top'><img src=$row[Small_Images] align='left' hspace='10' vspace='10' border='0' alt=\"$row[Product_Name]\"><strong><a href=$row[Buy_URL] target='_blank'>$row[Product_Name]</a></strong><br><br><strong>Price: $ $row[Price]</strong></td>
</tr>

</table>
";
} 



Quote:
This produces output that looks like:

Product 1
Product 2
Prodcut 3
Product 4

So only one column, multiple rows

I am trying to reformat that as:

Product 1 | Product 2 | Product 3
Product 4 | Product 5 | Product 6

Two or three columns, multiple rows.

Any ideas on how I could do this?
__________________
Web Hosting Tips | Career Advice
  #9  
Old 04-Dec-2003, 02:03
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I have just the thing for you; I use it to drive the categories menu on GIDTopsites™ : http://topsites.gidhelp.com/

You need to copy and paste the PHP class below and filename it, HGtable.lib.php
PHP Code:

<?php
/* *  AUTHOR      :  J de Silva
   *  WEBSITE     :  www.desilva.biz
   *  EMAIL       :  scripts[at]desilva[dot]biz
   *  COPYRIGHT   :  Gen.I Designs
   *  - - - - - - - - - - - - - - - - - - - - -
   *  FILE        :  /../includes/classes/HGtable.lib.php
   *  DATE        :  October 25th, 2002
   *  VERSION     :  
   *  ABOUT       :  HG = HTML Generator?  table = generates
                                       a HTML table!
   *  _________________________________________ */
class HGtable
{
        var $attrs;
        var $blank_cell;
        var $data_array;
        var $html;
        var $ttl_cols;
        var $ttl_data;
        var $ttl_rows;
        
        function HGtable()
        {
            register_shutdown_function( array($this, '_close') );
            $this->data_array        =    array();
            // default settings...
            $this->attrs['td']    =    '';
            $this->attrs['tr']    =    '';
            $this->blank_cell        =    '&nbsp;';
        }
        
        function addData( $cell_data )
        {
            $this->data_array[]    =    $cell_data;
            unset( $cell_data );
        }
        
        function getHTML()
        {
            $this->ttl_rows    = $this->_calc_rows();
            $this->_add_blank_cells_2_data_array();
            for( $tr=0; $tr<$this->ttl_rows; $tr++ )
            {
                $this->html    .=    '  <tr'.$this->attrs['tr'].">\r\n";
                    for( $td=0; $td<$this->ttl_cols; $td++ )
                    {
                        $this->html    .=    '    <td'.$this->attrs['td'].'>'.$this->_insert_cell_data()."</td>\r\n";
                    }
                $this->html    .=    "  </tr>\r\n";
            }
            unset( $tr, $td );
            return( $this->html );
        }
        
        function setBlankCell( $html )
        {
            $this->blank_cell    =    $html;
        }
        
        function setTagATTR( $tag, $attr )
        {
            $this->attrs[ $tag ]    =    ' '.$attr;
            unset( $tag, $attr );
        }
        
        function setTTLCOLS( $int )
        {
            $this->ttl_cols    =    intval( $int );
            unset( $int );
        }
        
        function _add_blank_cells_2_data_array()
        {
            $ttl_blank_cells    =    ( $this->ttl_rows * $this->ttl_cols ) - $this->ttl_data;
            if( $ttl_blank_cells )
            {
                for( $i=0; $i<$ttl_blank_cells; $i++ )
                {
                    $this->data_array[]    =    $this->blank_cell;
                }
                unset( $i );
            }
            unset( $ttl_blank_cells );
        }
        
        function _calc_rows()
        {
            $this->ttl_data    =    sizeof( $this->data_array );
            return( ceil($this->ttl_data / $this->ttl_cols) );
        }
        
        function _close()
        {
            unset( $this );
        }
        
        function _insert_cell_data()
        {
            $td = current( $this->data_array );
            @next( $this->data_array );
            return( $td );
        }   
}
?>


Then in your script example above, edit the bit to something like this:
PHP Code:

<?php
include_once( '/path/to/HGtable.lib.php' );
$tbl = new HGtable();
// how many columns in the table?
$tbl->setTTLCOLS( 2 );
// set any attribute for the <td> tag below
$tbl->setTagATTR( 'td', 'style="width:250px;vertical-align:top"' );
// set how the extra / blank cells will look like...
$tbl->setBlankCell( '<strong>Nothing Here</strong>' );
// start the table
echo '<table style="width:500px;border-collapse:collapse;border:none;">'."\r\n";
while( $row = mysql_fetch_assoc($result) )
{
    $tbl->addData( "<img src=$row[Small_Images] align='left' hspace='10' vspace='10' border='0' alt=\"$row[Product_Name]\" />".
                                    "<strong><a href=$row[Buy_URL] target='_blank'>$row[Product_Name]</a></strong><br />".
                                    "<br />".
                                    "<strong>Price: $ $row[Price]</strong>" );
}
// complete the table generation... 
$rows    = $tbl->getHTML();
echo $rows;
// close the table
echo '</table>';
?>

  #10  
Old 04-Dec-2003, 11:52
Div's Avatar
Div Div is offline
Moderator
 
Join Date: May 2002
Posts: 996
Div has a spectacular aura aboutDiv has a spectacular aura about
Thumbs up

Much nicer than my counter based try. Thanks.

ps - you should put this in the PHP library...cause I actually checked.
__________________
Web Hosting Tips | Career Advice
 
 

Recent GIDBlogA Week in Kuwait by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Adsense could mean death to affilliate programs jrobbio AdSense Forum 12 11-Feb-2006 15:51
premade forums and other premade php programs invaderz MySQL / PHP Forum 1 06-Jul-2003 02:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:15.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.