Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 15-11-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  PHP Help Needed

Hi Guys,

ok basically im calling products from the database and creating a table with 2 columns and echoing the products down the page

now it works on the 1st row .. and echos 2 products across but after that it echoes 1 product per row

the code is below
PHP Code:
 // Echo Products
 
echo ('<table width=\'590\'><tr>');
 
$i=0;
 while(
$result mysql_fetch_assoc($doresult)){
 echo (
'<td width=\'100\'>');
 
//Title Replace
 
$title str_replace('Dreamworks Beds, ','',$result['title']);
 echo (
'<h1><a href='.$result['url'].' class=\'listingtitle\'>'.$title.'</a></h1>');
 echo (
'<img width=\'100px\' height=\'100px\' src='.$result['image'].' align=\'absmiddle\'>');
 echo (
'<br>');
 echo (
'<div class=\'footerboxtxt\'>£'.$result['price'].'</div>');
 echo (
'<img src=\'kicon.jpg\' border=\'0\' alt=\'King Size Bed\'><a href='.$result['url'].' class=\'footerboxtxt\'><img src=\'addtocart.jpg\' border=\'0\' alt=\'Add To Cart\'></a><br>');
 echo (
'</td>');
 if(
$i==1) {
$i=0;
echo (
'</tr><tr>');
}
$i++;
}  
echo(
"</tr></table>"); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 15-11-07
tbp tbp is offline
Registered User
 
Join Date: Dec 2006
Posts: 1,999
Thanks: 0
Thanked 18 Times in 18 Posts
tbp is an unknown quantity at this point
  Re: PHP Help Needed

The problem comes from the section:

PHP Code:
if($i==1) {
  
$i=0;
  echo (
'</tr><tr>');
}
$i++; 
If $i = 1 then, you reset $i back to 0 which is fine. However, the next line then adds 1 to $i, so whereas it should be 0, its now set to 1.

Next time through the loop, after going through only once, its caught by the $i = 1 clause and the process repeats.

Put the $i++ in an else condition so it only adds 1 if $i is not equal to 1 eg

PHP Code:
if($i==1) {
  
$i=0;
  echo (
'</tr><tr>');
} else {
 
$i++;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 15-11-07
Registered User
 
Join Date: Sep 2007
Posts: 582
Thanks: 0
Thanked 0 Times in 0 Posts
cyates is an unknown quantity at this point
  Re: PHP Help Needed

goddammit lol

i spent 3 hours looking at the code and didnt even see the problem lol

many thanks tbp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 15-11-07
tbp tbp is offline
Registered User
 
Join Date: Dec 2006
Posts: 1,999
Thanks: 0
Thanked 18 Times in 18 Posts
tbp is an unknown quantity at this point
  Re: PHP Help Needed

No Problem!

Always difficult to find mistakes in your code, as you get "code blindness" lol, you see what you think it should be doing, rather than what it is actually doing.

It helps to print out the contents of variables in situations like this, so you can see whats going on at each step. If i`m creating complex code pages, then I add in debugging statements as I write the code, all triggered by a master variable at the top of the page. A much simplified example would be:

PHP Code:
$debug 0

if($debug == 1){
  echo 
"$i = " $i;

If the code doesn't do what you expect, just set $debug to 1, so it prints out all the variables at every step. Also makes it much easier if something breaks in the future (if your taking data from an external source), as you can just turn on debug and it helps to fix the problem much faster.

If you're happy that the page is working fine and won't change you can remove the debugging statements.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Product Datafeed - PHP Help Needed! Himore Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 10 30-10-07 04:46 PM
Php help needed!!! SIMONR85 Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 1 12-07-07 12:06 PM
Site needed in Php max99 Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 1 07-10-06 07:50 AM
PHP Help needed charlton Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 2 01-03-06 10:55 AM
PHP help needed on duplicate categories holmes Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 6 12-03-04 10:24 AM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7