Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Insert ad code into dynamic table
Old 12-06-2007, 01:14 AM Insert ad code into dynamic table
Novice Talker

Posts: 4
Name: Damon
Location: Canada
Trades: 0
My PHP skills are self-taught and this is my first real script so the solution is probably pretty simple. Please forgive me.

I am trying to insert ad code into a glossary that is stored in a MySQL database. Just to make things fun, the table alternates background colors based on code from this page.

The code seems to have some logic problems as it currently alternates glossary terms with ad code, but all the glossary terms are appearing correctly and the background colors are alternating as I would like.

PHP Code:
$query "SELECT term, definition FROM glossary ORDER BY term";
$result mysql_query($query);
$i 0;
$adcount 0;

print 
"<table cellspacing='0' cellpadding='4'>
  <col width='148' />
  <col width='476' />
   <tr bgcolor='#F4EFE8' height='12'>
      <td width='148' height='12'>Term</td>
      <td width='476'>Definition</td>
    </tr>"
;
    
while((
$row mysql_fetch_row($result)) !== false) {
    
$i++;
    
$adcount++;     
    print 
"<tr class=\"d".($i 1)."\">";   //alternates css style
    
print "<td>".$row[0]."</td>";
    print 
"<td>".$row[1]."</td>";
    print 
"<td>".$adcount."</td>";      //for debugging
    
print "</tr>\n";
     
  if (
$adcount == 5|11|17)                //show ad after the 5th, 11th, and 17th rows
   
{
       
$i++;
     
$adcount++;
    print 
" <tr class=\"d".($i 1)."\">";
    print 
" <td></td><td>adcode goes here</td>";
    print 
"<td>".$adcount."</td>";         //for debugging
    
print "</tr>\n";
    }
}
mysql_free_result($result);
print 
"</table>"
I appreciate any help.

Damon
AskOlliDamon is offline
Reply With Quote
View Public Profile Visit AskOlliDamon's homepage!
 
 
Register now for full access!
Old 12-06-2007, 02:31 AM Re: Insert ad code into dynamic table
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I don't think you can write an if statement as you did, although I'm not sure.
PHP Code:
if ($adcount == 5|11|17
Try this instead
</span></span>
PHP Code:
if ($adcount == || $adcount == 11 || $adcount ==17
</span></span>
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-06-2007, 05:18 AM Re: Insert ad code into dynamic table
Novice Talker

Posts: 4
Name: Damon
Location: Canada
Trades: 0
Thank you so much. That worked exactly as advertised.

d.
AskOlliDamon is offline
Reply With Quote
View Public Profile Visit AskOlliDamon's homepage!
 
Reply     « Reply to Insert ad code into dynamic table
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13733 seconds with 12 queries