/    Sign up×
Community /Pin to ProfileBookmark

Products catalogue format problem

Hey, im building a product catalogue web page which retrieve the info from mysql DB.
the idea is to have a table with 5 products in a row. each page got different number of product rows and the system dynamically create the rows.

I managed to work it out but… i still get some funny stuff going on.

The problem:

  • 1. The first row starts with an empty undefined <td>.

  • 2. The last row contains some empty undefined <td> as well.
  • Please take a look at what ive achieved so far at:
    (navigate to other products to see the problem on the other pages)

    And the code i wrote is:

    [code=php]
    echo “<div id=”products”>”;
    $query = “SELECT * FROM necklace ORDER BY ID”;
    $result = mysql_query($query) or die (“Query failed”);
    $num = mysql_num_rows($result); // = 37 total
    $thumbcols = 4; // specify how many in each row
    $thumbrows = 1 + round($num / $thumbcols);

    echo “<form action=’$PHP_SELF’ method=’POST’><input type=’hidden’ name=’op’ value=’show’>”;
    echo “<table>”;
    function display_table(){
    global $num, $result, $thumbrows, $thumbcols;

    for($r=1; $r<=$thumbrows; $r++){
    echo “<tr>”;
    // format the number of columns to be printed in each row using a 2nd for loop
    for($c=1; $c<=$thumbcols; $c++){
    echo “<td class=”thumb”>”;
    echo “<a href=’$PHP_SELF?op=show&code=$row[CODE]’><img src=”.$row[‘THUMB’].” border=”0″></img></a><br>”;
    $row = mysql_fetch_array($result); // break out the array of values from the returned query
    echo “</td>”;
    }
    echo “</tr>”;
    }
    }
    display_table();
    echo “</table>”;
    echo “</form>”;
    ?>
    [/code]

    Hope you guys can help me out.

    Thanks, Shooka

    to post a comment
    PHP

    7 Comments(s)

    Copy linkTweet thisAlerts:
    @bathurst_guyFeb 19.2006 — [code=php]
    echo "<a href='$PHP_SELF?op=show&code=$row[CODE]'><img src=".$row['THUMB']." border="0"></img></a><br>";
    $row = mysql_fetch_array($result);
    [/code]
    [/QUOTE]

    Your receiving the first error because you are trying to echo out $row when you havn't set it yet (done the line after)

    And you are receiving the last error because 37 / 4 does not result in a whole number.
    Copy linkTweet thisAlerts:
    @bathurst_guyFeb 19.2006 — From PM:Hi mate, sorry, dont understand what u mean.

    Could u explain?

    Tnx, Shooka[/QUOTE]
    Which part don't you understand, the first or the last or both?
    Copy linkTweet thisAlerts:
    @shookaauthorFeb 19.2006 — hi, again, just not sure u recieved my last post.

    the first row is fine now. just im getting funny results on the last row

    any idea how to sort it?

    u can see the page at:

    http://www.bellissimab.com/new/necklace.php
    Copy linkTweet thisAlerts:
    @bathurst_guyFeb 19.2006 — You could do this[code=php]for($c=1; $c<=$thumbcols; $c++){
    $row = mysql_fetch_array($result); // break out the array of values from the returned query
    if($row[CODE] != ""){
    echo "<td class="thumb">";
    echo "<a href='$PHP_SELF?op=show&code=$row[CODE]'><img src=".$row['THUMB']." border="0"></img></a><br>";
    echo "</td>";
    }else{
    echo "<td colspan=".($thumbcols-$c).">&nbsp;</td>";
    $c = $thumbcols + 1;
    }
    } [/code]
    Copy linkTweet thisAlerts:
    @shookaauthorFeb 19.2006 — Hi again, thats what i wrote and im getting only half of the products.

    it does solve the undefined <td> but...

    see it in:

    http://www.bellissimab.com/new/ring.php

    (there are origanlly 12 rings)

    Tnx, Shooka


    for($c=1; $c<=$thumbcols; $c++){

    $row = mysql_fetch_array($result);

    if($row[CODE] != ""){
    echo "<td class="thumb">";
    echo "<a href='$PHP_SELF?op=show&code=$row[CODE]'><img src=".$row['THUMB']." border="0"></img></a><br>";
    $row = mysql_fetch_array($result); // break out the array of values from the returned query
    echo "</td>";
    }else{
    $c = 5;
    echo "</tr>";
    }
    }
    }
    }
    Copy linkTweet thisAlerts:
    @bathurst_guyFeb 19.2006 — You have $row = mysql_fetch_array($result); in there twice...
    Copy linkTweet thisAlerts:
    @shookaauthorFeb 19.2006 — Mate, tnx a lot for your help.

    it looks perfect !!!
    ×

    Success!

    Help @shooka spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...