Jump to content

dropbop

Members
  • Posts

    34
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dropbop's Achievements

Member

Member (2/5)

0

Reputation

  1. I cant remember exactly why I did that, I really should start commenting on my code more... or I will end up lost in git myself lol A sub category is any category that has a parent. Categories can be as deep as we want, but we are sticking 1 sub level Parent Cat > Sub Cat Each cat have an ID and a Parent ID. category_id category_name parent_id cat_showing 1 Category One 0 0 2 Category Two 0 0 3 Sub Category One 1 0 4 Sub CategoryTwo 2 0 I suppose what I need to know/learn how to do is, to check the products table for any products that are in the sub categories of the selected (parent) category... So if a visitor was on category?cid=20 and some of its sub cats had no products, I would rather not show them the categories so I dont waste there time looking through pages that have nothing in them.
  2. Hi, I have been working on an eCommerce platform for the last few months. Its almost complete but I need to do one thing and thats to only display sub categories if products exist in them. This is the site craftgo.me (development site), and this is how the categories are produced for a category page. ie. http://www.craftgo.me/category.php?cat_id=96 if($_GET['cat_id']) { $parents_id = $_GET['cat_id']; $cat_num_rows_sql = "SELECT category_id, parent_id FROM mccategories WHERE parent_id = '$parents_id'"; $cat_num_rows_result = mysql_query($cat_num_rows_sql); $cat_row_count = mysql_num_rows($cat_num_rows_result); if($cat_row_count == '0'){ $current_cat_parent_sql = "SELECT parent_id FROM mccategories WHERE category_id = '$cat_id'"; $current_cat_parent_result = mysql_query($current_cat_parent_sql); $cat_parent_row = mysql_fetch_array($current_cat_parent_result); $parent_id = $cat_parent_row['parent_id']; } else { $parent_id = $_GET['cat_id']; } } $catsql = "SELECT category_id, category_name FROM mccategories WHERE cat_showing = '0' AND parent_id = '$parent_id' ORDER BY category_name"; $catresult = mysql_query($catsql); while($catrow = mysql_fetch_array($catresult)) { $category_id = $catrow['category_id']; $cat_name = $catrow['category_name']; echo '<li><a href="category.php?cat_id=' . $category_id . '">' . $cat_name . '</a></li>'; } In the mcproducts table the category id for each product is under 'product_category' Im not even sure where to start to make this work, but if anyone could give me a pointer, that would be super. Many thanks Eoin
  3. That works perfectly! thank you very much... I was initially trying to use JOIN, but from looking at your one, mine was all wrong.. but now I know how to do it properly. I did get an error though, which after googleing it, the error was saying there were 2 columns with 'showing', Column 'showing' in field list is ambiguous So just in case anyone else gets the same error after using a JOIN, it means there is a column in each table with the same name. I haven't tried it yet, but to get around it, you can put the table name before the column name, something like SELECT table1.showing, table2.showing...... please correct me if I'm wrong... I'm still learning myself. Anyway, thanks again scootsha.. problem solved!
  4. I was just pondering on this last night when editing a login page for a script im building.... cheers for the tip. DB
  5. Hi, I have been working on a directory/cms script (first large script to build from scratch). I am stuck on a small part of it where is shows users a list of the listings they have put in the directory. Below is the code that generates the table that shows the list of listings which is pulled from the 'listings' table in my database. <?php ### List of listings user has posted ### if(isset($_SESSION['userlogged'])) { $user_id = $_SESSION['userlogged']; $sqlCommand = "SELECT listing_id, cat_id, listing_title, listing_date, showing FROM listings WHERE showing='0' AND user_id='$user_id' ORDER BY listing_id ASC"; $query = mysql_query($sqlCommand,$con) or die (mysql_error()); $ListingDisplay = ''; while ($row = mysql_fetch_array($query)) { $listing_id = $row["listing_id"]; $cat_id = $row['cat_id']; if ($cat_id == '1') { $cat_name = "Carpenters"; } if ($cat_id == '2') { $cat_name = "Stone Masons"; } if ($cat_id == '3') { $cat_name = "Plumbers"; } if ($cat_id == '4') { $cat_name = "Landscapers"; } $listing_title = $row["listing_title"]; $listing_date = $row["listing_date"]; $ListingDisplay .= ' <tr class="listingaccount"> <td><a href="edit_listing.php?lid=' . $listing_id . '">' . $listing_id . '</a></td> <td>' . $cat_name . '</td> <td>' . $listing_title . '</td> <td>' . $listing_date . '</td> <td><a class="hoverBtn" href="edit_listing.php?lid=' . $listing_id . '"><img src="images/btnedit.png" border="0"></a></td> <td><a class="hoverBtn" href="remove_listing.php?lid=' . $listing_id . '"><img src="images/btndelete.png" border="0"></a></td> </tr>'; } mysql_free_result($query); ?> <table width="680" border="0" align="right" cellpadding="0" cellspacing="0"> <tr> <td colspan="2"><h2>My Listings</h2></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><a href="account_add_listing.php">Add New Listing</a></td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Listing Code</td> <td>Category</td> <td>Title</td> <td>Date Entered</td> <td> </td> </tr> <?php echo $ListingDisplay; ?> </table> </td> </tr> </table> <?php } ?> That all works just fine, but I would like to be able to generate the categories automatically. I am thinking some sort of array, but im not quite sure how to go about it and was hoping maybe someone could give me a starting point I could work from. My categories table is like this: -------------------------- | cat_id | cat_name | -------------------------- Many thanks Eoin
  6. Hi, Im not sure if it related to your issue, but you are missing a ' in this line to the left of $sproductcode $query = "INSERT into orders (customerid, productcode, quantity, productprice, orderdate) values ('$scustomerid', $sproductcode', '$squantity', '$sproductprice', '$sorderdate')"; Hop you get the problem fixed..
  7. I'm actually looking back into it again.. After looking at loads of other ways to resize images, Simple Image seems to be the best.. Thanks jcbones
  8. Ok, here is the finished product... Using the code Seany provided (which I am very grateful for), I have created the dropdown as follows... Below is a jpg of the finished dropdpown <select style="width:150px;" name="category"> <option value="">Select a Category</option> <?php //This selects all rows where Parent_id = 0 and ORDERS by category_name $parent_query = mysql_query("SELECT * FROM categories WHERE parent_id=0 ORDER BY category_name ASC"); while($parent=mysql_fetch_array($parent_query)){ $parent_id = $parent['category_id']; $parent_name = $parent['category_name']; echo "<option style=\"font-weight:bold;\">".$parent_name."</option>"; //This gets all the rows where the PARENT_ID = the parents category_id $child_query = mysql_query("SELECT * FROM categories WHERE parent_id=$parent_id ORDER BY category_name ASC"); while($child=mysql_fetch_array($child_query)){ $child_id = $child['category_id']; $child_name = $child['category_name']; echo "<option style=\"padding-left:15px;\" value=\"".$child_id."\">".$child_name."</option>"; } } ?> </select> [attachment deleted by admin]
  9. Thanks you Seany, I'm very grateful for your help. This looks like it could work perfectly.. now to get creating the dropdown... When I get the dropdown working, I will post the code here in case anyone else comes across a similar issue. Cheers.
  10. Hi, I don know how to explain this in words too well, so i have create 2 images to show what I need. What I need to do is use whats in the first image (table.jpg)(the database) to create whats in the second image (dropdown.jpg)(the drop-down menu) The results of the form will be entered into the database. category_id will be the value thats inserted. Many kind regards Eoin [attachment deleted by admin]
  11. ok, so I have managed to get the basics going.... <?php if(isset($_POST['Submit'])) { $current_image=$_FILES['image']['name']; $extension = substr(strrchr($current_image, '.'), 1); if (($extension!= "jpg") && ($extension != "jpeg")) { die('Unknown extension'); } $time = date("fYhis"); $new_image = "image_large_" . $time . "." . $extension; $new_image_small = "image_small_" . $time . "." . $extension; $destination="uploads/".$new_image; $destinationtwo="uploads/".$new_image_small; $action = copy($_FILES['image']['tmp_name'], $destination); $action = copy($_FILES['image']['tmp_name'], $destinationtwo); if (!$action) { die('File copy failed'); }else{ mysql_query("INSERT INTO customers (small_image, large_image) VALUES ('".$new_image_small."','".$new_image."')"); echo "File copy successful"; } ?> This works so far but is still a bit basic compared to what I need. Here I can upload a file, then save it as 2 files with different name in the uploads folder, and also add the names to the database. What I need to do now, is make one image small (approx 200px) and the other one large (Approx 600px). I have looked at that Simpleimage (Thanks jcbones) but it confuses me, is there a simpler way to change the size of an image that a bit less complicated for me? Thanks Eoin
  12. I have looked around all overr, but cant find what im looking for. Everything I have found is about uploading multile files, what I need to do is upload one file and copy it so there is 3 files. Here is an example of what I need to accomplish. Upload file picture1.jpg From picture1.jpg create 3 files - smallimage_picture1.jpg, largeimage_picture1.jpg & smallimage_picture1_thumb.jpg Each file will need to be copied to a /products directory and also an entry for each file name placed in mysql database table. I don't think this is as simple as it sounds to do in PHP, but i am very willing to learn so if anyone knows of a good tutorial that get get me started that would be super. regards DB
  13. A table was the first thing I tried, but it just showed everything in one long column. I would prefer to use tables to show results tho.
  14. Ah yes!!, well spotted, never even occured to me.... cheers for that. Here is what I have now and with a little help from css, I have it showing as many columns as will fit <?php mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $output = ""; $result = mysql_query("SELECT * FROM mcproducts ORDER BY RAND() LIMIT 10"); while($row = mysql_fetch_array($result)) { $products_local_id = $row['products_local_id']; $productname = $row['product_name']; $thumburl = $row['image_from_url']; $productlink = $row['product_local_url']; $thumbnail = $row['product_image_small']; $currencysymbol = $row['product_currency']; $price = $row['product_price']; $flagicon = $row['product_country_from']; $output = " <div class=\"productimage\"> <a href=".$productlink."".$products_local_id."><img src=".$thumburl."".$thumbnail." width=\"150\" height=\"150\"></a> </div> <div class=\"productdescription\"> <div class=\"pro_name\"> <a href=".$productlink."".$products_local_id.">".$productname."</a> </div> <div class=\"pro_description\"> </div> <div class=\"pro_description\">".$flagicon." ".$currencysymbol." ".$price."</div> </div> "; ?> <html> <head> <link href="style/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="displaybox"> <div class="productimage"> <a href="<?php echo $productlink; ?><?php echo $products_local_id; ?>"><img src="<?php echo $thumburl; ?><?php echo $thumbnail ?>" width="150" height="150"></a> </div> <div class="productdescription"> <div class="pro_name"> <a href="<?php echo $productlink ?><?php echo $products_local_id; ?>"><?php echo $productname; ?></a> </div> <div class="pro_description"> </div> <?php if ($flagicon=="Ireland") { $flagicon = "<img src=\"flags/ireland.jpg\">"; } elseif ($flagicon=="UK") { $flagicon = "<img src=\"flags/uk.jpg\">"; } else echo ""; ?> <div class="pro_description"><?php echo $flagicon; ?><?php echo $currencysymbol; ?> <?php echo $price; ?></div> </div> </div> <?php } ?> </body> </html> Thanks again AyKay47, that was a quick resonse from you... really appreciated indeed DB
  15. I was wondering how does one go about showing results from SELECT query in columns in a html table. I have a list of products in a table, and would like to show them on the page in 4 columns. I have done many searches on google to try and find the sulution, but the majority of what im finding instead is about displaying a table from phpmyadmin as a table in html. If its a large operation to do this, I would be very happy if someone could poiint me in the direction of a tutorial maybe. Here is the code I have so far to display the products, but for some reason, it only show 1 row instead of all the rows from my table. <?php $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "dbname"; mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $result = mysql_query("SELECT * FROM mcproducts"); while($row = mysql_fetch_array($result)) { $products_local_id = $row['products_local_id']; $productname = $row['product_name']; $thumburl = $row['image_from_url']; $productlink = $row['product_local_url']; $thumbnail = $row['product_image_small']; $currencysymbol = $row['product_currency']; $price = $row['product_price']; $flagicon = $row['product_country_from']; } ?> <html> <head> <link href="style/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="displaybox"> <div class="productimage"> <a href="<?php echo $productlink; ?><?php echo $products_local_id; ?>"><img src="<?php echo $thumburl; ?><?php echo $thumbnail ?>" width="150" height="150"></a> </div> <div class="productdescription"> <div class="pro_name"> <a href="<?php echo $productlink ?><?php echo $products_local_id; ?>"><?php echo $productname; ?></a> </div> <div class="pro_description"> </div> <?php if ($flagicon=="Ireland") { $flagicon = "<img src=\"flags/ireland.jpg\">"; } elseif ($flagicon=="UK") { $flagicon = "<img src=\"flags/uk.jpg\">"; } else echo ""; ?> <div class="pro_description"><?php echo $flagicon; ?><?php echo $currencysymbol ?> <?php echo $price ?></div> </div> </div> </body> </html> Many thanks, DB
×
×
  • 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.