graham23s Posted March 5, 2008 Share Posted March 5, 2008 Hi Guys, i was trying to wordwrap a piece of a description but then add a "more..." link after the finish to lead to a page where you can view the rest i have: $product_description_wrapped = wordwrap($product_description,20, "<a href="page.php?id=$id">More...</a>"); but it just loops the aboce wrapped over and over im not sure if it's because im in a while loop <?php // get the id // $categoryid = $_GET['id']; // query the db // $queryproduct = "SELECT * FROM `fcp_categories` WHERE `id`='$categoryid'"; $resultproduct = mysql_query($queryproduct) or die (mysql_error()); $row = mysql_fetch_array($resultproduct) or die (mysql_error()); // vars // $catname = $row['categoryname']; // set the rane // //$quantity = range(1,99); // get and display all the products associated with this cat // $queryproducts = "SELECT * FROM `fcp_products` WHERE `category_id`='$categoryid'"; $resultsproducts = mysql_query($queryproducts) or die (mysql_error()); // number of products // $numproducts = mysql_num_rows($resultsproducts); // standard header // print("<div class=\"subheader\"><div id=\"title\">Category > <span class=\"blue\">$catname</span></div>We have <b>$numproducts</b> products in this category for you to browse.</div>"); //--------------------------------------------// // need modulous to display them properly // $i = 0; // begin the table // print("<table class=\"products_table\" align=\"center\" width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">"); // start the while loop // while ($rows = mysql_fetch_array($resultsproducts)) { $productid = $rows['id']; $product_name = $rows['product_name']; $product_description = $rows['product_description']; $product_price = $rows['product_price']; // word warp // $product_description_wrapped = wordwrap($product_description,20); /*// display box for products // $display_box = "<form action=\"shoppingcart.php\" method=\"get\">\n"; $display_box .= "<div id=\"right\">\n"; $display_box .= "<div class=\"boxtop\">\n"; $display_box .= "</div>"; $display_box .= "<div class=\"box\">"; $display_box .= "<img src=\"images/image.gif\" alt=\"Product Image\" title=\"Product Image\" class=\"image\" />\n"; $display_box .= "<b><a href=\"productinformation.php?productid=$productid\">$product_name</a></b>"; $display_box .= "<br />"; $display_box .= "<br />"; $display_box .= "$product_description"; $display_box .= "<br />"; $display_box .= "<hr />"; $display_box .= "<input type=\"hidden\" name=\"productid\" value=\"$productid\" />"; $display_box .= "<input type=\"image\" src=\"images/cart_navy.gif\" border=\"0\" alt=\"Add this item to your shopping cart!\">"; $display_box .= "<hr />"; $display_box .= "Our Price <span class=\"price\">£$product_price</span>"; $display_box .= "<br />"; $display_box .= "<hr />"; $display_box .= "<b>Quantity:</b> "; $display_box .= "<select name=\"orderquantity\">"; $display_box .= "<option value=\"1\">1</option>"; $display_box .= "<option value=\"2\">2</option>"; $display_box .= "<option value=\"3\">3</option>"; $display_box .= "<option value=\"4\">4</option>"; $display_box .= "<option value=\"5\">5</option>"; $display_box .= "</select>"; $display_box .= "</div>\n"; $display_box .= "</div>\n"; $display_box .= "</div>\n"; $display_box .= "</form>\n"; */ // new display box 05/03/2008 // $display_box = "<form action=\"shoppingcart.php\" method=\"get\">\n"; $display_box .= "<div id=\"right\">\n"; $display_box .= "<div class=\"boxtop\">\n"; $display_box .= "</div>"; $display_box .= "<div class=\"box\">"; $display_box .= "<table width='250' border='1' bordercolor='#000000' cellpadding='5' cellspacing='0' />"; $display_box .= "<tr>"; $display_box .= "<td align='center'><img src=\"images/image.gif\" title='Product Image' alt='Product Image' /></td><td align='center'><b><a href='productinformation.php?productid=$productid'>$product_name</a></b></td>"; $display_box .= "</tr>"; $display_box .= "<tr>"; $display_box .= "<td colspan='2' align='center'>DESCRIPTION</td>"; $display_box .= "</tr>"; $display_box .= "<tr>"; $display_box .= "<td colspan='2' align='left'>$product_description_wrapped</td>"; $display_box .= "</tr>"; $display_box .= "</table>"; $display_box .= "</div>\n"; $display_box .= "</div>\n"; $display_box .= "</div>\n"; $display_box .= "</form>\n"; if ($i==0) { print('<tr><td align="center">'.$display_box.'</td>'); } elseif ($i == 2) { print('<td align="center">'.$display_box.'</td></tr>'); } else { print('<td align="center">'.$display_box.'</td>'); } $i++; $i=$i % 2; // mod 2 gives you the remainder // } // end the while loop // // end the products tabel // print("</tr>"); print("</table>"); // show the button if the session is set and the category has more than 0 items // // buttons // if(isset($_SESSION['id'])) { $session_id = $_SESSION['id']; // query the database if the session id has products in the basket show the button // $q = "SELECT `customer_id` FROM `fcp_orders` WHERE `customer_id`='$session_id'"; $r = mysql_query($q); if(mysql_num_rows($r) > 0 && $numproducts > 0) { print("<hr width=\"50%\">"); print("<form action=\"checkout.php\" method=\"post\">"); print("<table width=\"95%\" border=\"0\">"); print("<tr>"); print("<td align=center><img src=\"images/cards.bmp\" alt=\"Payments we accept!\"></td>"); print("<td align=center><input type=\"submit\" value=\"Proceed to Checkout\" style=\"font-weight: bold; font-size: 120%;\"></td>"); print("<input type=\"hidden\" name=\"step\" value=\"1\">"); print("</table>"); print("</form>"); } } ?> cheers Graham Link to comment https://forums.phpfreaks.com/topic/94578-wordwrapping-with-a-link/ Share on other sites More sharing options...
BrandonK Posted March 5, 2008 Share Posted March 5, 2008 1) Wordwrap() does not truncate the string, it merely makes it wrap after X characters. If you want to truncate the description, use substr() 2) You will get a product description for each product since you are looping through all of your products 3) Removing old/unused code, irrelevant code and intending your code can make understanding your code a lot easier for those trying to help you. Link to comment https://forums.phpfreaks.com/topic/94578-wordwrapping-with-a-link/#findComment-484395 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.