Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 03-07-08
Registered User
 
Join Date: Jun 2007
Posts: 220
Thanks: 8
Thanked 3 Times in 2 Posts
ChristopherB is an unknown quantity at this point
  php code question - example inc.

I'm just wondering if anyone can point out anything thats wrong with this php code. the weird thing is it works on my localhost (with correct database info) but doesn't work on my hosting (with correct database info aswell) no errors no text nothing. the page only loads up to this statement then stops.

PHP Code:
<?php
 
require_once('../mysqli_connect.php');

 
$q "SELECT * FROM products WHERE type='indoor' ORDER BY price ASC LIMIT 6";
 
$r = @mysqli_query ($dbc$q);

 if (
$r) {

 while (
$row mysqli_fetch_array($rMYSQLI_ASSOC)) {

 echo 
'        <div class="product_box">
         <div class="product_image"><a href="' 
$row['link'] . '"><img src="' $row['image_url'] . '" width="120" height="144" alt="' $row['name'] . '" /></a></div>
                 <div class="product_title"><a href="' 
$row['link'] . '">' $row['name'] . '</a></div>
                 <div class="product_retailer">From <a href="' 
$row['link'] . '">' $row['retailer'] . '</a></div>
                 <div class="product_description">' 
$row['extract'] . '</div> 
                 <div class="product_button"><a href="' 
$row['link'] . '"><img src="images/visit.jpg" alt="visit store" /></a></div>
                 <div class="product_price"><a href="' 
$row['link'] . '">&pound;' $row['price'] . '</a></div>
               </div>
     '
;

}

mysqli_free_result ($r);

} else {

echo 
'not working';

echo 
'<p>' mysqli_error($dbc) . 'Query:' $q '</p>';

}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-07-08
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 code question - example inc.

Does the host have mysqli installed? You might have it locally, but your host doesn't which could be causing the problem, as they may just have the mysql extension installed. (The two are slightly different)

Try removing the @ sign from mysqli_query, as the @ suppresses error messages which may tell you what the problem is.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-07-08
Registered User
 
Join Date: Jun 2007
Posts: 220
Thanks: 8
Thanked 3 Times in 2 Posts
ChristopherB is an unknown quantity at this point
  Re: php code question - example inc.

Thanks tbp i think you've nailed it on the head.

this seems to work fine

PHP Code:
<php ?
$result mysql_query("SELECT * FROM products where type='indoor' ORDER BY price ASC LIMIT 7")
or die(
mysql_error());  

// store the record of the "example" table into $row
$row mysql_fetch_array$result );
// Print out the contents of the entry 

while($row mysql_fetch_array($result)){

 echo 
'        <div class="product_box">
         <div class="product_image"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '"><img src="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' $row['image_url'] . '" width="120" height="144" alt="' $row['name'] . '" /></a></div>
                 <div class="product_title"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '">' $row['name'] . '</a></div>
                 <div class="product_retailer">From <a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '">' $row['retailer'] . '</a></div>
                 <div class="product_description">' 
$row['extract'] . '</div> 
                 <div class="product_button"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '"><img src="images/visit.jpg" alt="visit store" /></a></div>
                 <div class="product_price"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '">&pound;' $row['price'] . '</a></div>
               </div>
     '
;

}


?> 
however limiting by 7 produces 6 results, but with my mysqli one limiting by 6 produces 6 results. I am new to php and i learned using the mysqli functions, this is gonna be difficult. ;(
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-07-08
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 code question - example inc.

Just spotted the problem with your limit:

You have:

PHP Code:
//store the record of the "example" table into $row
$row mysql_fetch_array$result );
// Print out the contents of the entry 

while($row mysql_fetch_array($result)){

 echo 
'        <div class="product_box">
         <div class="product_image"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '"><img src="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' $row['image_url'] . '" width="120" height="144" alt="' $row['name'] . '" /></a></div>
                 <div class="product_title"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '">' $row['name'] . '</a></div>
                 <div class="product_retailer">From <a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '">' $row['retailer'] . '</a></div>
                 <div class="product_description">' 
$row['extract'] . '</div> 
                 <div class="product_button"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '"><img src="images/visit.jpg" alt="visit store" /></a></div>
                 <div class="product_price"><a href="http://www.affiliates4u.com/forums/affiliate-marketing-lounge/' 
$row['link'] . '">&pound;' $row['price'] . '</a></div>
               </div>
     '
;


The problem with this is that you first use mysql_fetch_array () to get the first record returned, which you store in $row.

However, next you use a while loop while mysql_fetch_array() is true. When the code execution gets to this point, it calls mysql_fetch_array() again for the first test to see if its true. This then overwrites the first record stored in $row before its printed to the screen, so for 7 results it would show 6 records.

Remove the line:

PHP Code:
$row mysql_fetch_array$result ); 
And it should work as intended, as the loop will start from the first record rather than the second.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 04-07-08
Registered User
 
Join Date: Jun 2007
Posts: 220
Thanks: 8
Thanked 3 Times in 2 Posts
ChristopherB is an unknown quantity at this point
  Re: php code question - example inc.

ahh i see, thankyou for explaining tbp you truely know your stuff. I was stuck for 3 hours trying to figure out why the mysqli functions would not work.

It was in my php book,

PHP 6 and MYSQL 5 which i used to learn it all, seems like my hosting company is using mysql 4 and php 4 without as you said mysqli installed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-07-08
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 code question - example inc.

Yes, PHP 6 isn't actually available as a release version yet The principles are the same though so won't make much difference.

You can get inconsistencies between hosts though, as there are so many versions of PHP and ways to configure it. You do sometimes have to adapt your code round the host, which is why I don't develop locally anymore and test on the host instead. As you've seen code can work on one server and not another, and it does make it frustrating trying to track the issue down.

Theres no excuse for the host to be using PHP 4 though. I know some do, but they definately aren't good ones.
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 On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Webgains weekly updated promotions Emma Delaforce Webgains 0 28-12-07 04:49 PM
Webgains updated weekly promotions Emma Delaforce Webgains 0 29-08-07 04:41 PM
Weekly Update: Webgains Current Promotions Emma Delaforce Webgains 0 23-08-07 11:39 AM
Webgains current promotions - weekly update Emma Delaforce Webgains 0 28-06-07 12:33 PM
using php to print TD javascript code J Nas Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 2 17-03-05 04:01 PM


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

Content Relevant URLs by vBSEO 3.2.0 RC7