Results 1 to 13 of 13
  1. #1
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    Creating 3 columns for products
    I just can't seem to get it to work. Could someone tell me what is wrong with my code?

    <?
    $user="[removed]";
    $host="localhost";
    $password="[removed]";
    $database="jacksret_jacksret2";
    $connection=mysql_connect($host,$user,$password)
    or die ("couldn't connect to server");
    $db=mysql_select_db($database,$connection)
    or die ("couldn't execute query.");
    $limit=6;
    $query_count="SELECT * FROM everythingfurniture where category like '%$interest%'";
    $result_count=mysql_query($query_count);
    $totalrows=mysql_num_rows($result_count);
    $page = $_GET['page'];

    if(empty($page))
    {
    $page = 1;
    }
    $limitvalue = ($page * $limit) - $limit;
    $query = "SELECT * FROM everythingfurniture where category like '%$interest%' order by name LIMIT $limitvalue,$limit";
    $result = mysql_query($query) or die("Error: " . mysql_error());

    ?>

    <table width="100%" border="0" align="center" cellpadding="5" cellspacing="5">
    <tr>


    <?php
    $prod_columns=3; // Alter this to change number of columns
    $loop_count = 1;
    while($row=mysql_fetch_array($result)){
    ?>

    <td width="<?php print 100/$prod_columns;>%" valign="top">

    <?

    if (!$result){
    echo "<p> Error performing query: mysql_error()
    </p>";

    exit();
    }
    while ($row = mysql_fetch_array($result) ) {

    echo "<a href={$row['buyurl']} title='{$row['name']}'><img src={$row['imageurl']} border='0' width='100' alt='{$row['name']}'></a><p>";
    echo "<b><a href={$row['buyurl']} title='{$row['name']}'>{$row['name']}</a></b>
    <br><a href={$row['buyurl']} title='{$row['name']}'><b>{$row['name']}</b></a><br>{$row['description']}<br><font color=red>Price: {$row['price']}</font><br><br><a href={$row['buyurl']} title='{$row['name']}'><font color=orange>Click Here For More Info</font></a><br>";

    echo "</td>";

    }

    if($loop_count == $prod_columns){
    ?>


    </tr>
    </table>


    <table width="100%" border="0" align="center" cellpadding="15" cellspacing="0">
    <tr>

    <?php
    $loop_count = 1;
    }else{
    $loop_count++;
    }
    $count++; // Just for making the while statement work
    }




    ?>

    </tr>
    </table>



    <table width=98% align=center>
    <tr>
    <td>

    <?
    $limit=6;
    if($page != 1){
    $pageprev = $page-1;
    }

    $numofpages = ($totalrows / $limit);
    for($i = 1; $i <= $numofpages; $i++){
    if($i == $page)
    echo($i." ");
    else
    echo("<a href=\"everythingfurniture-links.php?interest=$interest&page=$i\"><font size=1>$i</font></a> |
    ");
    }

    if(($totalrows % $limit) != 0){
    if($i == $page)
    echo(" ");
    else
    echo("<a href=\"everythingfurniture-links.php?interest=$interest&page=$i\"><font size=1>$i</font></a> |
    ");
    }

    if(($totalrows - ($limit * $page)) > 0){
    $pagenext = $page+ 1;

    }else

    mysql_free_result($result);

    ?>

    </td>
    </tr>
    </table>
    Last edited by Greg Rice; September 8th, 2006 at 09:40 AM. Reason: Removed login info

  2. #2
    ABW Ambassador Greg Rice's Avatar
    Join Date
    January 18th, 2005
    Location
    Ohio
    Posts
    4,889
    Jack, your db login info was included in your code so I removed it, assuming it was in there unintentionally.
    Greg Rice Affiliate Program Management
    www.gocmc.com info(AT)gocmc.com | 330-259-1223

    Join us! - MiNeeds.com | DiscountCandleShop/CheeseSupply | Feng Shui Plaza

  3. #3
    Full Member
    Join Date
    January 18th, 2005
    Location
    Moved, Asia
    Posts
    400
    if($loop_count == $prod_columns){
    ?>

    Something is missing.
    IRS
    Don't ask why the ball doesn't come.

  4. #4
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    isn't that where it's supposed to do the </tr></table> if those conditions are met?

  5. #5
    Full Member
    Join Date
    January 18th, 2005
    Location
    Moved, Asia
    Posts
    400
    OMG, sorry! Except in function show_data(), I never cut a query before itís finished. Good point for me, I can save in echoing.
    IRS
    Don't ask why the ball doesn't come.

  6. #6
    Full Member
    Join Date
    January 18th, 2005
    Location
    Moved, Asia
    Posts
    400
    I hope this one is correct:
    Missing a ? in <td width="<?php print 100/$prod_columns;>%" valign="top">

    ==> <td width="<?php print 100/$prod_columns; ?>%" valign="top">
    IRS
    Don't ask why the ball doesn't come.

  7. #7
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    well it was a nice thought but no change LOL

    It's almost like it's not ending and starting the next part f the table like it should

    ie it starts he table corrwctly but on th second record doesn't do a <td> and so forth

  8. #8
    Full Member
    Join Date
    January 18th, 2005
    Location
    Moved, Asia
    Posts
    400
    I think you have 1 over code of while($row=mysql_fetch_array($result)). Delete one under exit(); For the page display, I normally follow the Google structure, to limit them to only 20.
    IRS
    Don't ask why the ball doesn't come.

  9. #9
    ABW Veteran Mr. Sal's Avatar
    Join Date
    January 18th, 2005
    Posts
    6,795
    I just can't seem to get it to work. Could someone tell me what is wrong with my code?
    Jack,

    By using the code you have there, I made some modifications so you get an Idea about creating 3 columns for products, while this script is not perfect or complete, at least you can see how it could work.

    I will attach a 3columns-test.gif at the end, so you see what I got with this version of the script you posted above.


    Your same code modified a bit:
    ------------------------------------
    <?
    $user="[removed]";
    $host="localhost";
    $password="[removed]";
    $database="jacksret_jacksret2";
    $connection=mysql_connect($host,$user,$password)
    or die ("couldn't connect to server");
    $db=mysql_select_db($database,$connection)
    or die ("couldn't execute query.");
    $limit=4;
    $query_count="SELECT * FROM everythingfurniture where category like '%$interest%'";
    $result_count=mysql_query($query_count);
    $totalrows=mysql_num_rows($result_count);
    $page = $_GET['page'];
    if(empty($page))
    {
    $page = 1;
    }
    $limitvalue = ($page * $limit) - $limit;
    $query = "SELECT * FROM everythingfurniture where category like '%$interest%' order by name LIMIT $limitvalue,$limit";
    $result = mysql_query($query) or die("Error: " . mysql_error());
    ?>
    <table width="100%" border="1" align="center" cellpadding="5" cellspacing="5">
    <tr>
    <?php
    $prod_columns=3; // Alter this to change number of columns
    $loop_count = 1;
    while($row=mysql_fetch_array($result)){

    if (!$result){
    echo "<p> Error performing query: mysql_error()
    </p>";
    exit();
    }
    while ($row = mysql_fetch_array($result) ) {
    echo "<td width=\"33%\" valign=\"top\"><a href={$row['buyurl']} title='{$row['name']}'><img src={$row['imageurl']} border='0' width='100' alt='{$row['name']}'></a><p>";
    echo "<b><a href={$row['buyurl']} title='{$row['name']}'>{$row['name']}</a></b>
    <br><a href={$row['buyurl']} title='{$row['name']}'><b>{$row['name']}</b></a><br>{$row['description']}<br><font color=red>Price: {$row['price']}</font><br><br><a href={$row['buyurl']} title='{$row['name']}'><font color=orange>Click Here For More Info</font></a><br>";
    echo "</td>";
    }
    if($loop_count == $prod_columns){
    ?>
    </tr>
    </table>
    <table width="100%" border="0" align="center" cellpadding="15" cellspacing="0">
    <tr>
    <?php
    $loop_count = 1;
    }else{
    $loop_count++;
    }
    $count++; // Just for making the while statement work
    }
    ?>
    </tr>
    </table>
    <table width=98% align=center>
    <tr>
    <td>
    <?
    $limit=100;
    if($page != 1){
    $pageprev = $page-1;
    }
    $numofpages = ($totalrows / $limit);
    for($i = 1; $i <= $numofpages; $i++){
    if($i == $page)
    echo($i." ");
    else
    echo("<a href=\"everythingfurniture-links.php?interest=$interest&page=$i\"><font size=1>$i</font></a> |
    ");
    }
    if(($totalrows % $limit) != 0){
    if($i == $page)
    echo(" ");
    else
    echo("<a href=\"everythingfurniture-links.php?interest=$interest&page=$i\"><font size=1>$i</font></a> |
    ");
    }
    if(($totalrows - ($limit * $page)) > 0){
    $pagenext = $page+ 1;
    }else
    mysql_free_result($result);
    ?>
    </td>
    </tr>
    </table>
    ------------------------------------
    Attached Images Attached Images

  10. #10
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    IRS:

    Thank you that did the trick

    Sal:

    Is there any important difference between what you posted and just taking the 2nd fetch out?

  11. #11
    Full Member
    Join Date
    January 18th, 2005
    Location
    Moved, Asia
    Posts
    400
    jackson992:

    No problem. If I may suggest, change 100/$prod_columns into floor(100/$prod_columns).
    IRS
    Don't ask why the ball doesn't come.

  12. #12
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    Hi IRS:

    Could you tell me what the difference is? What does the added floor command do?

  13. #13
    Full Member
    Join Date
    January 18th, 2005
    Location
    Moved, Asia
    Posts
    400
    Using floor, the result will be rounded down. In your case, width="33.333333333333%" become width="33%".
    IRS
    Don't ask why the ball doesn't come.

  14. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Creating database of all products in country with images , desc and UPC.
    By zikr in forum Programming / Datafeeds / Tools
    Replies: 11
    Last Post: February 18th, 2014, 02:59 PM
  2. missing columns in overstock
    By PatrickAllmond in forum Rakuten LinkShare - LS
    Replies: 0
    Last Post: April 27th, 2007, 12:48 AM
  3. Tables and Columns
    By jwg in forum WebMerge (Fourthworld.com)
    Replies: 1
    Last Post: February 11th, 2005, 03:41 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
  •