Jump to content

googlit

Members
  • Posts

    52
  • Joined

  • Last visited

Everything posted by googlit

  1. Try This <?php echo "<tr>"; echo "<td align='center'>" . $row["ID"] . "</td>"; echo "<td align='center'>" . $row["Name"] . "</td>"; echo "<td align='center'>" . $row["jobNO"] . "</td>"; echo "<td align='center'>" . $epn . "</td>"; echo "<td align='center'>" . $cname . "</td>"; echo "<td align='center'><a href=\"link.php?id=['$link']\">' . $cadd . '</a></td>"; //want to add a hyperlink here echo "</tr>"; echo "</table>"; ?>
  2. install xammp if your using windows, then start playing with some code, i was where you are 8 months ago and my knowledge and help from my colegues/friends has helped no end. if you need any help let PM me and i will do all i can, if you a need a basis to start i have some scripts for logins etc that i used when learning PHP (when i jumped in the deep end) and these are well commented and simple to grasp! i'm not an expert but i will help if possiable! Have fun and welcome
  3. hi all, i have a script in where the user enters there post code and it will provide a price for delivery, how would i echo "please contact us for price" if the db record for the price is (null) or empty?? <?php mysql_connect ("localhost", "root","password") or die (mysql_error()); mysql_select_db ("postcode"); $term = $_POST['term']; $sql = mysql_query("SELECT * FROM uk_postcodes, zones WHERE postcode LIKE '%$term%' AND zone_id = zone_large "); while ($row = mysql_fetch_array($sql)){ echo '<br/> Postcode: '.$row['postcode']; echo '<br/> Town: '.$row['town']; echo '<br/> County: '.$row['county']; echo '<br/> Small: £'.$row['price_s']; echo '<br/> Medium: £'.$row['price_m']; echo '<br/> Large: £'.$row['price_l']; echo '<br/><br/>'; } ?>
  4. hi the code was used from an example provided on this post: http://www.phpfreaks.com/forums/index.php/topic,310186.msg1464976.html#msg1464976
  5. Hi can any body give me an idea why i am receiving the following errors from my script? Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 29 Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 44 Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 29 Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 44 Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 29 Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 44 Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 50 script is: <?php include_once "include/globals.php"; if (isset($_GET['cat-id'])) { $id = $_GET['cat-id']; } ?> <?php //Get database Results $result = mysql_query("SELECT * FROM Products WHERE is_active = 1 AND catagory_id = $id ") or die(mysql_error()); if(mysql_num_rows($result)===0) { $output = "No records found.\n"; } else { $output = "<table>\n"; //keeps getting the next row until no more records $recNo = 0; while($row = mysql_fetch_array($result)) { $recNo++; //Start new row when needed if($recNo%$max_columns==1) { $output .= "<tr>\n"; } //Create TD for record $output .= "<td><div class=\"table-bg\">"; $output .= "<div class=\"title\">{$row['Name']}</div>"; $output .= "<div class=\"image\">"; $output .= "<a href=\"product_detail.php?id=\"><img src=\"{$row['image']}\" width=\"100\" alt=\"\" border=\"0\"></a>"; $output .= "</div>"; $output .= "<div class=\"tag_line\">{$row['Tag_Line']}</div>"; $output .= "<div class=\"price\">Now Only: £{$row['Website_Price']}</div>"; $output .= "<div class=\"prod-footer\"><a href=\"product_detail.php?id={$row['ID']}\">more info</a></div>"; $output .= "</div></td>\n"; //Close row when needed if($recNo%$max_columns==0) { $output .= "</tr>\n"; } } //Close final row if needed if($recNo%$max_columns!=0) { $output .= "</tr>\n"; } $output .= "<table>\n"; } ?> <div id="main"> <?php echo $output; ?> </div> <div class="table-bg"></div>
  6. thanks for that, i always looked at tables as 'going back in time' i spent so much time learning css so i would have a better way to disply pages that i now virtually ignore the use of tables as 'div' tags are far more flexible.
  7. Hi, im creating a script for a website that will list products, i have the basic construct which lists the products from the database but it lists then vertically, i have set the width of each 'product' to 200px so i could have around 3 colums and many rows. can anybody advise how i would make them run horizontally aswell as vertically? my code below: <?php include_once("include/globals.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styles/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <?php //Get database Results $result = mysql_query("SELECT * FROM Products WHERE is_active = 1") or die(mysql_error()); //keeps getting the next row until no more records while($row = mysql_fetch_array($result)) { //echo results ($result) echo '<div id="holder">'; echo '<div class="title">' . $row['Name'] . '</div>'; //insert image here echo '<div class="image">'; echo '<a href="product_detail.php?id="><img src="' . $row['image'] . '" width="100" alt="" border="0"></a>'; echo '</div>'; echo '<div class="tag_line">'; echo $row['Tag_Line']; echo '</div>'; echo '<div class="price">Now Only: £'; echo $row['Website_Price']; echo '</div>'; echo '<div class="prod-footer">'; echo "<a href=\"product_detail.php?id={$row['ID']}\"> more info </a></li>"; echo '</div>'; echo '</div>'; } ?> </div> </body> </html>
  8. ok so for the second issue of the night, has anyone used lightbox with images that are fetched from a database (mysql)?? i have the following but it opens at the bottom of the page and not in a lightbox... echo '<a href="' . $row['image'] . '" rel="lightbox[roadtrip]"><img src="' . $row['image'] . '" width="100" alt=""></a>'; full code on attachment [attachment deleted by admin]
  9. Well persaverance prevailed!! (not sure if i can spell tho!! its late) the result is below: <?php //Get database Results $result = mysql_query("SELECT * FROM Products WHERE is_active = 1") or die(mysql_error()); //keeps getting the next row until no more records while($row = mysql_fetch_array($result)) { //echo results ($result) echo '<div id="holder">'; echo '<div class="title">' . $row['Name'] . '</div>'; //insert image here echo '<div class="image">'; echo '<a href="product_detail.php?id="><img src="' . $row['image'] . '" width="100" alt="" border="0"></a>'; echo '</div>'; echo '<div class="tag_line">'; echo $row['Tag_Line']; echo '</div>'; echo '<div class="price">Now Only: £'; echo $row['Website_Price']; echo '</div>'; echo '<div class="prod-footer">'; echo "<a href=\"product_detail.php?id={$row['ID']}\"> more info </a></li>"; echo '</div>'; echo '</div>'; } ?>
  10. ok, got the layout right but my CSS wont repeat/loop and i cant see where im going wrong...... <div id="main"><?php $query = "SELECT * FROM Products WHERE is_active = 1"; $result = mysql_query($query) or die(mysql_error()); // add all the rows into the $results multi-dimensional array $results = array(); while ($row = mysql_fetch_assoc($result)) $results[] = $row; /* Here is how we output the results vertically */ // set the number of columns $cols = 3; // work out how many rows will be needed $rows = ceil(count($results) / $cols); echo '<div id="holder">'."\n"; // output the rows for($j = 0; $j < $rows; $j++) { echo " <tr>\n"; // output the columns for($i = 0; $i < $cols; $i++) { $x = ($i*$rows)+$j; if(isset($results[$x])) { $row = $results[$x]; echo '<div class="title">'.$root.''.$row['Name'].'</div><div class="image">'.'<a href="product_detail.php?id="><img src="' . $row['image'] . '" width="100" alt="" border="0"></a></div>'.'<div class="tag_line">'.$row['Tag_Line'].'</div><div class="price">'.$row['Website_Price']. "</div>\n" . '<div class="prod-footer"></div>'; } else { echo " \n"; } } echo " \n"; } echo '</div>';?>
  11. getting there...... got the content now just got to apply the CSS styles to it....... :-\
  12. hi, thanks for that, i will give it a go..... still getting to grips with loops etc if possiable could you supply an example based on my code? if not no worries i will crack it eventually thanks for your help
  13. Hi, im creating a script for a website that will list products, i have the basic construct which lists the products from the database but it lists then vertically, i have set the width of each 'product' to 200px so i could have around 3 colums and many rows. can anybody advise how i would make them run vertically aswell as horizontally? my code below: <?php include_once("include/globals.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styles/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <?php //Get database Results $result = mysql_query("SELECT * FROM Products WHERE is_active = 1") or die(mysql_error()); //keeps getting the next row until no more records while($row = mysql_fetch_array($result)) { //echo results ($result) echo '<div id="holder">'; echo '<div class="title">' . $row['Name'] . '</div>'; //insert image here echo '<div class="image">'; echo '<img src="' . $row['image'] . '" width="100" alt="">'; echo '</div>'; echo '<div class="tag_line">'; echo $row['Tag_Line']; echo '</div>'; echo '<div class="price">Now Only: £'; echo $row['Website_Price']; echo '</div>'; echo '<div class="prod-footer"></div>'; echo '</div>'; } ?> </div> </body> </html> table structure: Field Type Null Default Comments MIME ID int(11) No product_code varchar(255) No Name varchar(255) Yes NULL Tag_Line varchar(255) Yes NULL Description varchar(255) Yes NULL Specification varchar(255) Yes NULL Technical_Info varchar(255) Yes NULL Cost_Price_USD decimal(10,2) Yes NULL Cost_Price_GBP decimal(10,2) Yes NULL Built_in_delivery decimal(10,2) Yes NULL Trade_Price decimal(10,2) Yes NULL Trade_Plus_Price decimal(10,2) Yes NULL Website_Price decimal(10,2) Yes NULL Is_active int(1) No image varchar(255) Yes NULL
  14. would the line already in it not do this?? $total += $Price * $qty;//method for total man im confused........ish
  15. Hi i use the following, which could be adapted for your needs: to echo "you have X items in your cart use the following: <?php // Include functions require_once('functions.php'); ?> //echo cart message <?php echo writeShoppingCart(); ?> you will need to include the following in your functions file: <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>Your basket is empty.</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping basket</a></p>'; } } ?> you will need to edit the variables to match your requirements, but should hopefully help you out...
  16. Hi i am creating a shopping basket and am running into a few problems, the main one that for the world in me i cant figure out is why when i add two different items to cart/basket does my sub-total not pick up the second item, it works perfectly with one product (and multiples of same product through qty) but not with two or more........... i've included the code from my functions which handles most of the math etc and my cart.php functions.inc.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>Your basket is empty.</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping basket</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table width="780" border="0">'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM Products WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; //$output[] = '<td> </td>'; //$output[] = '<td>Model No</td>'; //$output[] = '<td>Name</td>'; //$output[] = '<td>Price (Ex-VAT)</td>'; //$output[] = '<td>VAT</td>'; //$output[] = '<td>Qty</td>'; //$output[] = '<td>Total</td>'; //$output[] = '</tr> //<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';//remove from cart $output[] = '<td>'.$Model_No.'</td>';//echo model number $output[] = '<td>'.$Name.'</td>';//echo name $output[] = '<td>'.round($Price / 1.175, 2).'</td>';//echo price ex VAT $output[] = '<td>'.round(($Price / 47)*7, 2).'</td>';//echo VAT $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';//Qty box $output[] = '<td>£'.($Price * $qty).'</td>';//line total $output[] = '</tr> <tr>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; } $output[] = '<td><div align="right">Sub Total:</div></td>'; $output[] = '<td> </td>'; $output[] = '<td>£'.$Price.'</td>';//Sub-total formula to follow $output[] = '</tr> <tr>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td><div align="right">VAT Total:</div></td>'; $output[] = '<td> </td>'; $output[] = '<td>£'.round(($price_ex_VAT = $Price * 40 / 47) * $qty, 2).'</td>';//echo total VAT amount for order $output[] = '</tr> <tr>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td> </td>'; $output[] = '<td><div align="right">Grand Total:</div></td>'; $output[] = '<td> </td>'; $total += $Price * $qty;//method for total $output[] = '<td><strong>£'.$total.'</strong></td>';//display grand total $output[] = '</tr>'; $output[] = '</table>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> cart.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Shopping Basket</title> <link rel="stylesheet" href="css/styles.css" /> </head> <body> <div id="shoppingbasket"> <div id="sb-top"> <h1>Your Shopping Basket</h1> <?php echo writeShoppingCart(); ?> </div> <div id="sb-mid"> <h1>Please check quantities...</h1> <table width="780" border="0"><tr><td width="90"> </td> <td width="117">Model No</td> <td width="123">Name</td> <td width="116">Price (Ex-VAT)</td> <td width="139">VAT</td> <td width="50">Qty</td> <td width="115">Total</td> </tr></table> <?php echo showCart(); ?> </div> <p><a href="member-index.php">Back to products...</a></p> </div> </body> </html> any help would be once again greatly appreciated.....
  17. Thanks sasa, that worked well, not sure why i didn't think off that....
  18. Thanks but all that is is a formated Price from the session with two decimal points, i need something a bit more technical..... which book are you reading? may be woth a look..... thanks for the help.
  19. hi, im trying to edit my shopping basket code to display prices ex-vat (17.5%) and to display the vat amount What i have so far: Price of an item = $Price quantity of an item = $qty //sum to display vat amount - reduced to two decimal places £'.round(($Price / 47) * 7, 2).' //sum to display price ex vat - reduced to two decimal places £'.round($Price / 1.175, 2).' what i need to do now is display a sub-total with the following: total price ex-vat - - Price minus VAT * Qty total vat amount - - for this i had £'.round((($Price / 47) * 7) * $qty, 2).' which didnt work any help would be received well....... Thanks
  20. Thanks... Worked perfik! LOL cheers
  21. Got the image working however no there are double quotes displaying in the browser at the beginning of the 'NAME' output and then a set of double quotes immediately after the image. (see image attached) my code is as follows: <?php $sql = 'SELECT * FROM products WHERE catagory_id=' . intval($_GET['id']);//catagory id 1 = wine fridges $result = $db->query($sql); $output[] = ''; while ($row = $result->fetch()) { $output[] = '<div class="product-box"><div class="pbox-inner"><h1>"' .$row['Name'] .'<img src="images/'.$row['image'].'" width="70">' .'"</h1><br /><b>Model No: </B> ' .$row['Model_No'] .'<br /><b>Description: </b>' .$row['Description'] .'<br /><b>Price: </b>£' .$row['Price'] .'<br /> </div><div class="pbox-adtocart"> <div align="right"><a href="cart.php?action=add&id='.$row['id'].'"><img src="images/moreinfo.jpg" border="0" /></a></div></div> </div>'; } $output[] = ''; echo join('',$output); ?> [attachment deleted by admin]
  22. Fantastic!! thanks for your help... i was up till stupid o'clock this morning looking at this and it was really annoying me......
  23. thanks for that, i tried that previously but kept getting error, think i was commenting out wrong...... also when i display this in the browser the 'Name' form the data base is enclosed with double quotes which i cant seem to get rid of...... any ideas?
  24. If youve read of any of my previous posts you will know that i am new to PHP & MySQL and just getting to grips with it.... my question today is relatively straight forward i have a page which is product_detail.php, this page displays all the database info as i wish and is working perfctly with the following query: $sql ='SELECT * FROM products WHERE id=1' my question is is there a way that i can get it to work dynamically eg if the URL is www.domain.com/product_detail.php?id=2 it will display the no-2 record in the table? i have search high and low for a 'How to' on this so i am able to learn but i'm not 100% on what i should be looking for.... i know this can be done...... if anybody can point me in the right direction???? cheers
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.