Results 1 to 14 of 14
  1. #1
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Php Mysql - Repeating..??
    Just wanted to know if someone could point out what the problem is..
    I think I have looked at this to long.. I can't see the forest for the trees..

    I have a script that creates detail pages from a MYSQL database..

    It works fine.. accept that the HTML is repeated about ten times on the end results PHP page.. Each instance of the HTML that is supposed to be shown starts and ends in html /html so they are complete pages.. just repeated ten times...

    This is the script that creates the pages
    (What is inside the link-config.php is only the directory paths and the database username and password to access the MYSQL portion)
    Code:
     
    <?php
    include "link-config.php" ;
    $linkdb = mysql_connect("$link_host", "$mysql_login", "$mysql_password");
    mysql_select_db("$mysql_database",$linkdb);
    $displayresult = mysql_query("SELECT * FROM product_links",$linkdb);
    while ($myrow = mysql_fetch_array($displayresult)) {
    $filename = $myrow["sku"] . ".php";
    $secondline = "include " . chr(34) . "template.php" . chr(34);
    $newfile = "<" . chr(63) . "php
    ";
    $newfile = $newfile . " ". chr(36) ."passthrusku = " . $myrow["sku"] . " ;\n
    ";
    $newfile = $newfile . "include " . chr(34) . "template.php" . chr(34) . ";\n
    ";
    $newfile = $newfile . chr(63) . ">";
    $zfile = $fullpath . $filename;
    $databasefile = $dirname . $filename;
    echo $zfile . " " . $newfile;
    if ($file=fopen("$zfile", "a")) {
     fputs($file, $newfile);
    }
    }
    mysql_close($linkdb);
    ?>

    This is the beginning and end of the template page..
    Code:
     
    <?
    include "link-config.php" ;
    $linkdb = mysql_connect("$link_host", "$mysql_login", "$mysql_password");
    mysql_select_db("$mysql_database",$linkdb);
    $displayresult = mysql_query("SELECT * FROM product_links WHERE SKU='$passthrusku'",$linkdb);
    while ($myrow = mysql_fetch_array($displayresult)) {
    ?>
    HTML AND OTHER VARIABLES GO HERE...
    <?
    }
    mysql_close($linkdb);
    ?>
    Any help would be appreciated..

  2. #2
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    PHP Code:
    while ($myrow mysql_fetch_array($displayresult)) {
    ?>
    HTML AND OTHER VARIABLES GO HERE... 
    Looking at this part, the problem seems to be that it's being told to repeat all the HTML each time it finds a record.

    You should put the parts of the HTML that you *don't* want repeated, outside of any While loops. I've got my page template split into a header and footer that are called seperately. Then I put the dynamic part in between the two, and when the page is called up live it reassembles the parts into a working page.

    Near the top of my pages, before any loops, I've got
    PHP Code:
    include_once ('includes/header.html'); 
    And after the end of the loop it's
    PHP Code:
    include_once ('includes/footer.html'); 
    There is no knowledge that is not power. ~Hemingway

  3. #3
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Hey Thanks Leader...
    I'll try that.. very much appreciated..

    I'll let you know if this works..!

    BUT..
    it's not doing it for every record.. it is only doing it for the one record..
    but that one records data is repeated over around ten times then it stops..

    It's wierd that it doesn't loop through more records.. and the fact that it stops after ten times....
    I'll keep pounding on it until I get it to work correctly...

    Probably something very simple I just haven't seen yet....
    Last edited by AddHandler; May 6th, 2005 at 01:40 AM.

  4. #4
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    It could be your query, which is assuming that only one product is going to have any particular SKU.

    PHP Code:
    SELECT FROM product_links WHERE SKU='$passthrusku' 
    Which, in a perfect world, would be an okay assumption if only one merchant's selection is involved. But it's not a perfect world as we know!

    Some merchants have the horrid habit of putting multiple lines of the same product into their feed (Duplicates). If your merchant(s) did that, your query will return more than one item. Then your While loop will go on to list 'em all.

    In that scenario, the "multiple results" would really be from duplicate feed entries, and you'd end up with what looked like the same thing repeated again and again...

    You could try

    PHP Code:
    SELECT DISTINCT FROM product_links WHERE SKU='$passthrusku' 
    Which would block true, *exact* duplications of records.
    But often merchants don't just have easy-to-code-for duplications. There'll be something, in some field, that's different so the program thinks the records are ALL "distinct."

    In that case, you need to add more criteria to your SELECT statement to make sure you've got the right item:

    PHP Code:
    SELECT DISTINCT FROM product_links WHERE SKU '$passthrusku' AND Something_Else_That_Oughtta_Be_Unique '$other_variable' 
    Update--One hitch I just thought of:

    If you've got JC Whitney.
    They've got thousands and thousands of records in their feed with nothing different *except the SKUs!* Selecting by SKU with them will definitely produce dupes, in fact they'd generate exactly what you're seeing.... The only way I've found to deal with them is to
    PHP Code:
    SELECT DISTINCT FROM product_links WHERE SOMETHING_ELSE_NOT_THE_SKU='$passthru_notthesku' 
    Which of course will clash with any site that's been set up to use the SKU.

    But for the sites that I have multiple merchants and PHP on (which are set up to use the SKU, and I have no inclination to change that, at least not now), I handle them easily, with
    Code:
    DELETE FROM tablename WHERE programname = "JC Whitney";


    Their feed-generated pages can play in my car-parts ghetto, with their 4000 or so products and their 105,000 records which list them. And list them, and list them, without ever saying just what's different enough to warrant a new SKU! (It's actually stuff like different colors and such, I checked on their site. But their feed doesn't have that info, or at least it didn't the last time I looked at it!)
    Last edited by Leader; May 6th, 2005 at 04:41 AM.
    There is no knowledge that is not power. ~Hemingway

  5. #5
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Leader.. very much appreciated --
    BUT it didn't work...
    I am using one datafeed about 5000 products no duplicates in the database at all...

    But it just repeats the same SKU info over and over....

    I can't figure out why it's looping again and again..
    and
    Why it stops after about ten repeats....
    If it was stuck in a loop wouldn't it just loop forever...??


    I have looked at the output file and it is the same exact info repeated...


    It's LOOPY...
    I'll get it somehow.. It's probably something small.. a character out of place or something like that... I am just missing it... I'll put it down for awhile and come back with a fresh head and eyes.. se if I can spot it then..!

    Do you use a book for PHP... I have a book put it's not that good.. any reference guide for PHP available...??

  6. #6
    ABW Ambassador cditty's Avatar
    Join Date
    January 18th, 2005
    Location
    Memphis TN
    Posts
    1,434
    Have you tried just running the sql statemment in something like phpMyAdmin and seeing how it returns?
    Recycled Talent - Architects of custom scripts and snippets, perfectly written to suit any need. We stay on top of the latest technology so you don't have to.
    Total Stupidity - Shining light on stupid things.

  7. #7
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    cditty - no I haven't tried that... I don't know that much about phpMyAdmin just enough to do serious damage.. LOL


    Leader - I even replaced the "WHILE" with an "IF" and it still repeats itself..

    I'll get it to only make ONE if it kills me... screw the fresh eyes... I am working on it now and I am not putting it up until I get it to do what I want... LOL

  8. #8
    Affiliate Marketer Rogi's Avatar
    Join Date
    January 18th, 2005
    Location
    Melbourne
    Posts
    415
    Have you tried putting some 'echo' in a few spots to test it

    like try putting echo "Got to here" etc etc
    before and after the loop. see if it exits the loop and goes back in, in which case
    you're calling that function or file multiple times.

    also.... try include_once instead of include:
    include "link-config.php" ; --> include_once "link-config.php" ;

  9. #9
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    OK...
    I got it to stop repeating...
    It seems that it was a missing } at the end....

    Why ??? this was making it loop over and over baffles me.. but I guess without the one single } it didn't know to stop...


    Thanks for everyones input... very much appreciated on this end..!!!!
    now I can get to work... LOL getting the script working is just the beginning...!


  10. #10
    Affiliate Marketer Rogi's Avatar
    Join Date
    January 18th, 2005
    Location
    Melbourne
    Posts
    415
    That code you pasted doesn't seem to be missing any }'s
    It's weird.... you didn't get any parse errors, etc?

    Ah, it doesn't matter. It's working. Back to work

  11. #11
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Rogi - that is what baffles me.. it didn't give any errors it just looped about ten to fifteen times..

    The } may not have even been the problem.. to tell you the truth I can't really pin down exactly what I did.. but it is working now.. LOL

    It may have been something else I accidently took out while trying all the above examples I was given to try.. I narrowed it down to be within ten lines of the code and just started messing with that portion until it worked correctly....

    You got me why it didn't give me any errors... it should have I agree..
    But it is working

  12. #12
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    Thumbs up Ah Ha..
    AH HA...

    I really wanted to pin down what this problem was.. and I am glad I did because it is not fixed.. LOL..

    It seems that the script will create the file perfectly every single time..
    BUT.. if I run the script AGAIN -- in other words I make a change to the template page and then run it again.. it ADDS the data to the page..
    it doesn't overwrite the page... so if I run the script ten times it gets added to the page ten times instead of making a new page... does that make sense..??

    Now I will just have to make it overwrite the old page instead of adding to it..
    I thought I was going nutz.. it worked then it didn't - then it worked again.. or seemed to.....

    LOL - that'll teach me to get straight out of bed and start looking at a script.. best to wait until I have had at least a little caffiene..

  13. #13
    Resident Genius and Staunch Capitalist Leader's Avatar
    Join Date
    January 18th, 2005
    Location
    Florida
    Posts
    12,817
    it doesn't overwrite the page... so if I run the script ten times it gets added to the page ten times instead of making a new page... does that make sense..??
    This is just a guess, but it could be a default behavior; maybe it always will simply add to a page if it finds that the file will already exist.(/guess)

    Do you use a book for PHP... I have a book put it's not that good.. any reference guide for PHP available...??
    As for a PHP book, I've got PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide by Larry Ullman, which I used for the PHP part. IMO it's pretty good and better than what I saw in the local stores. There's more to learn (I don't agree with the claims I remember reading on the cover, that the book will make people into "advanced" programmers) but I think it's a good book. It made the basic conventions of PHP clear so I could dynamic-ize my sites, and it's not utterly baffling to look at PHP code anymore.

    The book's got MySQL, too, but since I started using MySQL (directly through the command line, on a local installation) long before I started tackling PHP, I didn't use that part of the book. I learned most the MySQL commands that I use from the tutorial that's in the MySQL docs (http://dev.mysql.com/doc/mysql/en/tutorial.html ) and other parts of their docs (for things that their little example DB doesn't cover), and when something comes up that I don't know I go fishing. First I go fishing in the docs, and if that's too Greek I hit Google.

    One thing nice about MySQL is that most of their docs are actually understandable--or at least, the parts where they actually EXPLAIN things instead of just listing all possible syntaxes for a command, are understandable.
    There is no knowledge that is not power. ~Hemingway

  14. #14
    ABW Ambassador AddHandler's Avatar
    Join Date
    January 19th, 2005
    Posts
    1,270
    I fixed it.. It just needed to be told to delete the file based on the SKU.. then create a file based on the SKU.. it wasn't bad...

    Thanks for the tips Leader.. I'll check it out..!


  15. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP and MySQL Knowledge
    By scm21st in forum Midnight Cafe'
    Replies: 5
    Last Post: August 5th, 2007, 10:30 PM
  2. looking for php/mysql work
    By spiderninja in forum Midnight Cafe'
    Replies: 0
    Last Post: January 31st, 2007, 11:12 PM
  3. Grouping with PHP and MySQL
    By Doug247 in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: March 24th, 2005, 10:07 AM
  4. PHP & mySQL but....
    By perfectG in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: November 6th, 2002, 06:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •