Jump to content

davids_media

Members
  • Posts

    58
  • Joined

  • Last visited

Everything posted by davids_media

  1. where is the type list where I may have listed the product as an integer (i am still quite new at the mo to php)
  2. i've managed to sort out that particular issue (i named one of my fields in table incorrectly) but now my 'product' field writes a 0 value when it should input whatever characters i insert into the text box
  3. I have some code where I am inserting a record into a database. <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('./includes/config.inc.php'); require_once (MYSQL); $add_cat_errors = array(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Check for a name: if (empty($_POST['product'])) { $add_cat_errors['product'] = 'Please enter the name!'; } // Check for a description: if (empty($_POST['prod_descr'])) { $add_cat_errors['prod_descr'] = 'Please enter the description!'; } // Check for a category: if (!isset($_POST['cat']) || !filter_var($_POST['cat'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $add_product_errors['cat'] = 'Please select a category!'; } // Check for a price: if (empty($_POST['price']) || !filter_var($_POST['price'], FILTER_VALIDATE_FLOAT) || ($_POST['price'] <= 0)) { $add_cat_errors['price'] = 'Please enter a valid price!'; } // Check for an image: if (is_uploaded_file ($_FILES['image']['tmp_name']) && ($_FILES['image']['error'] == UPLOAD_ERR_OK)) { $file = $_FILES['image']; $size = ROUND($file['size']/1024); // Validate the file size: if ($size > 512) { $add_cat_errors['image'] = 'The uploaded file was too large.'; } // Validate the file type: $allowed_mime = array ('image/gif', 'image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png'); $allowed_extensions = array ('.jpg', '.gif', '.png', 'jpeg'); $image_info = getimagesize($file['tmp_name']); $ext = substr($file['name'], -4); if ( (!in_array($file['type'], $allowed_mime)) || (!in_array($image_info['mime'], $allowed_mime) ) || (!in_array($ext, $allowed_extensions) ) ) { $add_cat_errors['image'] = 'The uploaded file was not of the proper type.'; } // Move the file over, if no problems: if (!array_key_exists('image', $add_cat_errors)) { // Create a new name for the file: $new_name = (string) sha1($file['name'] . uniqid('',true)); // Add the extension: $new_name .= ((substr($ext, 0, 1) != '.') ? ".{$ext}" : $ext); // Move the file to its proper folder but add _tmp, just in case: $dest = "../db/images/$new_name"; if (move_uploaded_file($file['tmp_name'], $dest)) { // Store the data in the session for later use: $_SESSION['image']['new_name'] = $new_name; $_SESSION['image']['file_name'] = $file['name']; // Print a message: echo '<h4>The file has been uploaded!</h4>'; } else { trigger_error('The file could not be moved.'); unlink ($file['tmp_name']); } } // End of array_key_exists() IF. } elseif (!isset($_SESSION['image'])) { // No current or previous uploaded file. switch ($_FILES['image']['error']) { case 1: case 2: $add_cat_errors['image'] = 'The uploaded file was too large.'; break; case 3: $add_cat_errors['image'] = 'The file was only partially uploaded.'; break; case 6: case 7: case 8: $add_cat_errors['image'] = 'The file could not be uploaded due to a system error.'; break; case 4: default: $add_cat_errors['image'] = 'No file was uploaded.'; break; } // End of SWITCH. } // End of $_FILES IF-ELSEIF-ELSE. // Check for a stock: if (empty($_POST['stock']) || !filter_var($_POST['stock'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $add_cat_errors['stock'] = 'Please enter the quantity in stock!'; } if (empty($add_cat_errors)) { $query = 'INSERT INTO product (product, product_descr, catID, price, image, stock) VALUES (?, ?, ?, ?, ?, ?)'; // Prepare the statement: $stmt = mysqli_prepare($dbc, $query); // For debugging purposes: // if (!$stmt) echo mysqli_stmt_error($stmt); // Bind the variables: mysqli_stmt_bind_param($stmt, 'isssdi', $name, $desc, $_POST['cat'], $_POST['price'], $_SESSION['image']['new_name'], $_POST['stock']); // Make the extra variable associations: $name = strip_tags($_POST['product']); $desc = strip_tags($_POST['prod_descr']); // Execute the query: mysqli_stmt_execute($stmt); if (mysqli_stmt_affected_rows($stmt) == 1) { // If it ran OK. // Print a message: echo '<h4>The product has been added!</h4>'; // Clear $_POST: $_POST = array(); // Clear $_FILES: $_FILES = array(); // Clear $file and $_SESSION['image']: unset($file, $_SESSION['image']); } else { // If it did not run OK. trigger_error('The product could not be added due to a system error. We apologize for any inconvenience.'); unlink ($dest); } } // End of $errors IF. } else { // Clear out the session on a GET request: unset($_SESSION['image']); } // End of the submission IF. require_once ('./includes/form_functions.inc.php'); ?> <form enctype="multipart/form-data" action="add_product.php" method="post" accept-charset="utf-8"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" /> Product<br /><?php create_form_input('product', 'text', $add_cat_errors); ?> Description<br /><?php create_form_input('prod_descr', 'textarea', $add_cat_errors); ?> Category<br /><select name="cat"<?php if (array_key_exists('cat', $add_cat_errors)); ?>> <option>Select One</option> <?php // Retrieve all the categories and add to the pull-down menu: $q = 'SELECT catID, cat FROM category ORDER BY cat ASC'; $r = mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; // Check for stickyness: if (isset($_POST['cat']) && ($_POST['cat'] == $row[0]) ) echo ' selected="selected"'; echo ">$row[1]</option>\n"; } ?> </select><?php if (array_key_exists('cat', $add_cat_errors)) echo $add_product_errors['cat']; ?> Price<br /><?php create_form_input('price', 'text', $add_cat_errors); ?> Image<br /><?php // Check for an error: if (array_key_exists('image', $add_cat_errors)) { echo $add_cat_errors['image'] . '<br /><input type="file" name="image"/>'; } else { // No error. echo '<input type="file" name="image" />'; // If the file exists (from a previous form submission but there were other errors), // store the file info in a session and note its existence: if (isset($_SESSION['image'])) { echo "<br />Currently '{$_SESSION['image']['file_name']}'"; } } // end of errors IF-ELSE. ?> Stock<br /><?php create_form_input('stock', 'text', $add_cat_errors); ?> <input type="submit" value="Add This Product" class="button" /> </fieldset> </form> However, I have a problem - i get this error message; An error occurred in script 'C:\Users\David Morgan\Desktop\WEBSITES\hairz_&_graces\site\admin\add_product.php' on line 124: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given How do I solve this as I think I have everything in place (variable associations, etc)?
  4. thats kind of what I am already doing (or at least wanting to do), hence the reason why I went down the path of using varchar as a field type, the files are already stored in directories and I just want to write the entire directory e.g. ('thumbs/thumb1.jpg')
  5. I want users to be allowed to upload images to a table in a database but I cannot seem to find a suitable way to implementing using the code I already have, here is the code below; <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('./includes/config.inc.php'); require_once (MYSQL); $add_cat_errors = array(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['product'])) { $prod = mysqli_real_escape_string($dbc, strip_tags($_POST['product'])); } else { $add_cat_errors['product'] = 'Please enter a Product Name!'; } if (filter_var($_POST['prod_descr'])) { $prod_descr = mysqli_real_escape_string($dbc, strip_tags($_POST['prod_descr'])); } else { $add_cat_errors['prod_descr'] = 'Please enter a Product Description!'; } // Check for a category: if (filter_var($_POST['cat'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $catID = $_POST['cat']; } else { // No category selected. $add_page_errors['cat'] = 'Please select a category!'; } if (filter_var($_POST['price'])) { $price = mysqli_real_escape_string($dbc, strip_tags($_POST['price'])); } else { $add_cat_errors['price'] = 'Please enter a Product Description!'; } if (filter_var($_POST['stock'])) { $stock = mysqli_real_escape_string($dbc, strip_tags($_POST['stock'])); } else { $add_cat_errors['stock'] = 'Please enter a Product Description!'; } if (empty($add_cat_errors)) { $query = "INSERT INTO product (product, prod_descr, catID, price, image, stock) VALUES ('$prod', '$prod_descr', '$catID', '$price', '$image', '$stock')"; $r = mysqli_query ($dbc, $query); if (mysqli_affected_rows($dbc) == 1) { echo '<p>Record Successfully Added!!!!!</p>'; $_POST = array(); } else { trigger_error('OH NOOOOO!!!!'); } } } require_once ('./includes/form_functions.inc.php'); ?> <form action="add_product.php" method="post"> Product Name: <?php create_form_input('product', 'text', $add_cat_errors);?> Product Description: <?php create_form_input ('prod_descr', 'text', $add_cat_errors);?> Category: <select name="cat"<?php if (array_key_exists('cat', $add_cat_errors))?>> <option>Select a Category</option> <?php $q = "SELECT catID, cat FROM category ORDER BY cat ASC"; $r = mysqli_query($dbc, $q); while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { echo "<option value=\"$row[0]\""; if (isset($_POST['cat']) && ($_POST['cat'] == $row[0])) echo 'selected="selected"'; echo ">$row[1]</option>\n"; } ?> Price: <?php create_form_input('price', 'text', $add_cat_errors);?> Upload an Image: <?php if(array_key_exists('image', $add_cat_errors)) { echo '<input type="file" name="image" />'; } ?> Stock: <?php create_form_input('stock', 'text', $add_cat_errors);?> <input type="submit" name="submit_button" value="ADD RECORD" /> </form> Everything else writes perfectly but I have been trying ways to create a file upload and write successfully to the database. The 'image' field has a data type of 'varchar'. I apologise immensely for the long winded explanation but if anyone could help me please that would be much appreciated.
  6. I am trying to find a simple solution to page my records Here is the code thus far below <?php $title = "Pick your Product"; //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require_once ('./includes/config.inc.php'); require_once (MYSQL); include ('./includes/header.html'); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image`, `product`.`stock` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { echo "<table class='table-container'>"; //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['cat_descr'] . "</h2>"; $showHeader = false; //Set index var to track record count $recIdx = 0; $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}' title='{$row['product']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; if ($row['stock'] < 2) // If there less than two items in stock!! { echo " (<span> Low in Stock! </span>) "; } elseif ($row ['stock'] = 0) { echo "Sorry, currently not available but we will try hard to get more in!"; } echo "</td>"; //Close row if needed if($recIdx % $maxCols == 1) { echo "</tr>"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>"; } //Close table & div } echo "</table>"; echo "</div>"; include ('./includes/footer.html'); ?> Theres no pagination thus far but can I possibly embed it into the code I have please?
  7. yes, its data type is set to decimal(6,2) and every record has a price, each of which are different
  8. I have an Add To Cart button in my website so when a user adds an item to a paypal cart, it directs from webpage to test store as a variable is passed. Here is the code; <p> <form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="item_name" value="<?php echo $row['product']; ?>"> [quote]Works perfectly[/quote] <input type="hidden" name="amount" value="<?php echo $row['price']; ?>">[quote]Works NOT SO perfectly[/quote] <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </p> The "item_name" type passes variable value to test store perfectly. So if a user adds item "shoes" to cart, its passes that item fine. But it should also pass the appropriate product price too (e.g. £1.99) but it does not. How can I solve this please as my code looks fine except for that bit.
  9. I have this code which I created last week of a dynamic html data driven table using php. <?php $title = "Pick your Product"; //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { echo "<table>"; //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['cat_descr'] . "</h2>"; $showHeader = false; //Set index var to track record count $recIdx = 0; $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}' title='{$row['product']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; echo "</td>"; //Close row if needed if($recIdx % $maxCols == 1) { echo "</tr>"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>"; } //Close table & div } echo "</table>"; echo "</div>"; include ('./includes/footer.html'); ?> I now want to incorporate an jquery carousel effect similar to this effect (its an image carousel though); http://sorgalla.com/projects/jcarousel/examples/special_flexible.html I know how to embed actual html script tages and actual javascript code into php but just not able to find the best practice possible to use it with my data table. help would be much appreciated
  10. last week I was finally able to create a dynamic php table with data. now I want to expand on it; here is the code; <?php $title = "Pick your Product"; //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { echo "<table>"; //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['cat_descr'] . "</h2>"; $showHeader = false; //Set index var to track record count $recIdx = 0; $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}' title='{$row['product']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; echo "</td>"; //Close row if needed if($recIdx % $maxCols == 1) { echo "</tr>"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>"; } //Close table & div } echo "</table>"; echo "</div>"; include ('./includes/footer.html'); ?> what I want is to apply a horizontal sliding effect for this table, so instead of paging for more results, just scroll across with next/previous buttons using jquery. this is something I would really like to do but I am having real trouble with it at the moment. any help would be much appreciated.
  11. I have a page which displays an item based on a search. Below is the code. <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['prodID'])) { $query = "SELECT `prodID`, `product`, `prod_descr`, `image`, `price` FROM product WHERE `prodID`='{$_GET['prodID']}'"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<div id='item'>"; // div class 'item' echo "<div class='item_left'>"; echo "<p>"; echo $row['prod_descr']; echo "</p>"; echo "<p>"; echo "&pound" . $row['price']; echo "</p>"; echo "</div>"; echo "<div class='item_right'>"; echo "<img src='db/images/".$row['image']."' />"; $showHeader = false; echo "<br />"; echo "You may also like...."; echo $row['product']; echo "</div>"; } } ?> <p> <form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="item_name" value="<?php echo $row['product']; ?>"> <input type="hidden" name="item_number" value="<?php echo $row['prodID']; ?>"> <input type="hidden" name="amount" value="<?php echo $row['price'] ?>" /> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </p> <?php echo "</div>"; // End of div class 'item' echo "</div>"; } include ('./includes/footer.html'); ?> What I want to achieve is just below the product content, is a feature with one or two random records which will essentially say to the user "you may also like" and display random but similar products. How do I achieve this?
  12. I have an online store where users can either purchase products or add them to carts for future purchasing. Here is the code for item.php <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['prodID'])) { $query = "SELECT `prodID`, `product`, `prod_descr`, `image`, `price` FROM product WHERE `prodID`='{$_GET['prodID']}'"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['prod_descr'] . "</h2>"; echo "<img src='db/images/".$row['image']."' />"; $showHeader = false; $price = $row['price']; $product = $row['product']; echo '<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="item_name" value="<?php echo $product; ?>"> <input type="hidden" name="amount_x" value="<?php echo $price; ?>"> <input type="hidden" name="hosted_button_id" value="7UCL9YCYYXL3J"> <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form>'; } } echo "</div>"; } include ('./includes/footer.html'); ?> It displays a product based from a search made. Here is what I want to do? (I have already created test accounts, buttons, etc using PayPal Sandbox) 1. Dynamically pass a variable from when I add a chosen item 2. When my cart loads in Sandbox testing, display the appropriate price, product name, etc, based on the variable or value passed. When I set this up (Add To Cart button) I created default item name and price values, yet I do not want to do this manually using Sandbox. I apologise is this appears rather confusing and still being someone relatively new to PHP, I could do with a better understanding of this but I need some serious help please with this dilemma.
  13. I've managed to sort thankfully, all i needed to do to retain my columns was to adjust some css inline display, thank you muddy_funster and david am for your help
  14. i have managed to get all rows back (i disposed of the second while loop), however, my table layout (see this post: http://www.phpfreaks.com/forums/index.php?topic=357406.0) has now messed up completely here is the code now <?php //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { echo "<table>"; //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['cat_descr'] . "</h2>"; $showHeader = false; //Set index var to track record count $recIdx = 0; $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; echo "</td>"; //Close row if needed if($recIdx % $maxCols == 0) { echo "</tr>"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>"; } //Close table & div } echo "</table>"; echo "</div>"; include ('./includes/footer.html'); ?>
  15. I have just tried moving that out, but it has made absolutely no difference whatsoever
  16. I have a problem with some code at the moment <?php //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $num_rows = mysqli_num_rows($r); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['cat_descr'] . "</h2>"; $showHeader = false; } //Open table echo "<table>"; //Set index var to track record count $recIdx = 0; while($row = mysqli_fetch_array($r)) { $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; echo "</td>\n"; //Close row if needed if($recIdx % $maxCols == 0) { echo "</tr>\n"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>\n"; } //Close table & div echo "</table>"; echo "$num_rows Rows\n"; echo "</div>"; } } include ('./includes/footer.html'); ?> I want to retrieve all my records based from my query search, however, it ignores the first record in the set and goes straight into the second record. I have six records based on this search, however, only five records are displayed even though I have done a mysql_num_rows which returns a value to state that there are six records. how do i solve this problem
  17. <?php //Set number of columns to use $maxCols = 3; error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`prodID`, `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); $num_rows = mysqli_num_rows($r); $showHeader = true; echo "<div id='right'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['cat_descr'] . "</h2>"; $showHeader = false; } //Open table echo "<table>"; //Set index var to track record count $recIdx = 0; while($row = mysqli_fetch_array($r)) { $recIdx++; //Open new row if needed if($recIdx % $maxCols == 1) { echo "<tr>"; } //Display product echo "<td>"; echo "<img src='db/images/".$row['image']."' height=150px width=150px /><br>"; echo "<li>" . "<a href='item.php?prodID={$row['prodID']}'>" . $row['product'] . "</a>" . "</li>"; echo "<span>" . "£". $row['price'] . "</span>"; echo "</td>\n"; //Close row if needed if($recIdx % $maxCols == 0) { echo "</tr>\n"; } } //Close last row if needed if($recIdx % $maxCols == 0) { echo "</tr>\n"; } //Close table & div echo "</table>"; echo "$num_rows Rows\n"; echo "</div>"; } } include ('./includes/footer.html'); ?>
  18. I did that, I created a variable called num rows and assigned it to the mysqli_num_rows, then in turn i created an echo of the variable, says I have six rows but only 5 are actually displayed.
  19. i have managed to get the layout ok, but not all of my records (based on the catID) have loaded. i have six records related to the catID(id number 7) but only four records have been display
  20. what i want is the layout of the data table to be like this websites; http://www.riverisland.com/Online/men/just-arrived
  21. UPDATE!! silly me forgot to include a while loop in my code to fetch an array, i've got it working properly now thanks
  22. I changed that, but in item.php i now have a problem which states that row ($row) is an undefined variable
  23. I have two pages - one called category (cat.php) and one for products (item.php). I am currently having a dilemma - i want to click on a particular product from category page and view more of that product information in item.php Here is the code for the two pages; <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); //Create flag variable to determine if header needs to be displayed $showHeader = true; echo "<div id='right'>"; echo "<table cellpadding='5' cols='2'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>" . "\n"; echo "<h2>" . $row['cat_descr'] . "</h2>" . "\n"; $showHeader = false; } //Display product name echo "<tr>"; echo "<td>". "<li>". "<a href='item.php?product={$row['product']}'>" . "<img src='db/images/".$row['image']."' height=50px width=50px />" . "</a>" . "</li>" . "</td>"; echo "<td>". "<li>" . "<a href='item.php?product={$row['product']}'>" . $row['product'] . "</a>" . "</li>" . "</td>"; echo "<td class='price'>" . "£". $row['price'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</div>"; } include ('./includes/footer.html'); ?> <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['prodID'])) { $query = "SELECT prodID, product, product_descr, image FROM product"; $r = mysqli_query($dbc, $query); $showHeader = true; echo "<div id='right'>"; if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['product'] . "<span>" . " #" . "</span>" . "</h1>"; echo "<h2>" . $row['prod_descr'] . "</h2>"; $showHeader = false; } echo "</div>"; } include ('./includes/footer.html'); ?> in item.php, when i want to view product information, using the echo, nothing is displayed on the page, how do i solve this?
  24. I want to create a table with data populated from a query. At the moment, I have have 8 records, however I want to have three columns and I want the layout like this; Name Age Name Age Name Age Here is the code thus far? <?php error_reporting(E_ALL ^ E_NOTICE); ini_set("display_errors", 1); require ('includes/config.inc.php'); include ('./includes/header.html'); require (MYSQL); include ('./includes/main.html'); if($id = isset($_GET['catID'])) { //Create and run query to get product category names for the selected cat ID $query = "SELECT `product`.`product`, `category`.`cat`, `product`.`prod_descr`, `category`.`cat_descr`, `product`.`price`, `product`.`image` FROM `product` LEFT JOIN `category` ON `product`.`catID` = `category`.`catID` WHERE `product`.`catID`='{$_GET['catID']}' ORDER BY `product`.`product`"; $r = mysqli_query($dbc, $query); //Create flag variable to determine if header needs to be displayed $showHeader = true; echo "<div id='right'>"; echo "<table cellpadding='5' cols='2'>"; while($row = mysqli_fetch_array($r)) { if($showHeader) { //Display category header echo "<h1>" . "<span>" . "# " . "</span>" . $row['cat'] . "<span>" . " #" . "</span>" . "</h1>" . "\n"; echo "<h2>" . $row['cat_descr'] . "</h2>" . "\n"; $showHeader = false; } //Display product name echo "<tr>"; echo "<td><img src='db/images/".$row['image']."' height=50px width=50px /></td>"; echo "<td>". "<li>" . "<a>" . $row['product'] . "</a>" . "</li>" . "</td>"; echo "<td class='price'>" . "£". $row['price'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</div>"; } include ('./includes/footer.html'); ?> how do I achieve this properly?
×
×
  • 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.