Jump to content

Murdock

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male

Murdock's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I previously encountered a similar scenario; this may be of some use. $last_title = ''; foreach ($items as $item) { if($item['title'] != $last_title) { echo $item['title']; echo $item['tag']; } else { echo $item['tag']; } $last_title = $item['title']; }
  2. I know you marked this as solved but thanks largely to a forum member on SitePoint and another here as well, I was pointed to a solution in a slightly different way and figured it was worth a share. My query returns: id product_id section_title section_description sort_order image_name sort_order -------|----------------|-------------------|-------------------------|----------------|----------------|---------------- 1 1 attribute 1 description of attr1 1 image1.1 1 1 1 attribute 1 description of attr1 1 image1.2 2 1 1 attribute 1 description of attr1 1 image1.3 3 2 1 attribute 2 description of attr2 2 image2 2 3 1 attribute 3 description of attr3 3 NULL NULL Similar to your situation, attribute 1 is repeated three times because a table I joined contains three images for it. Here is what I did: $last_title = ''; foreach ($items as $item) { if($item['section_title'] != $last_title) { echo $item['section_title']; echo $item['section_description']; echo $item['image_name']; } else { echo $item['image_name']; } $last_title = $item['section_title']; }
  3. Excellent, thanks savister! It didn't even occur to me to try something like that. I've only previously just looped through results and output them. This is what led me to believe I may have taken the wrong approach altogether.
  4. Hi all, First and foremost, I'm still quite new to relational database design and PHP in general so any thoughts, suggestions or input is greatly appreciated. I'm working on setting up a product catalog with three tables: product, product_attributes and product_images which are setup like so. product product_attributes product_images -----------------|------------------------------|------------------------- id id id item_title item_id attribute_id item_subtitle section_title image_name item_description section_description item_video sort_order item_category A product can have as many attributes as necessary and each attribute can also have as many images as desired. The goal is to output something like this: ITEM TITLE Subtitle Item overview/description Attribute 1 - paragraph about attribute 1 - image1.1, image1.2, image1.3 Attribute 2 - paragraph about attribute 2 - image2.1 Attribute 3 - paragraph about attribute 3 - no images included My limited knowledge produced the following query (I've just started using INNER JOIN): $query = 'SELECT ... FROM product_attributes AS t1 INNER JOIN product_images AS t2 ON t1.id = t2.attribute_id WHERE t1.product_id = 1 ORDER BY t1.sort_order'; this is what is returned. id product_id section_title section_description sort_order image_name sort_order -------|----------------|-------------------|-------------------------|----------------|----------------|---------------- 1 1 attribute 1 description of attr1 1 image1.1 1 1 1 attribute 1 description of attr1 1 image1.2 2 1 1 attribute 1 description of attr1 1 image1.3 3 2 1 attribute 2 description of attr2 2 image2 2 3 1 attribute 3 description of attr3 3 NULL NULL Attribute 1 has three rows; one for each image. This presents a unique challenge for me as I am not sure if it's the most appropriate query (I imagine probably not) or how to loop through the results to achieve the desired outcome above. Is there a better way to approach this and/or any suggestions on improving the overall table design? Thanks for your time.
  5. You may be getting only one image because of your file input name. Try: <input type="file" name="uploadFile[]"... Doing this: <form method="post" action=""> <input type="file" name="uploadFile[]" class="custom-upload" multiple="multiple" /> <input type="submit" name="submit" value="Submit"> </form> Returned this: /* if(isset($_POST['submit'])) { echo '<pre>'; var_dump($_POST); echo '</pre>; } */ array(2) { ["uploadFile"]=> array(4) { [0]=> string(10) "Desert.jpg" [1]=> string(12) "Penguins.jpg" [2]=> string(10) "Tulips.jpg" [3]=> string(13) "Jellyfish.jpg" } ["submit"]=> string(6) "Submit" }
  6. Hi guys, After a bit more research and generally poking around I managed to get it resolved. For some reason the server didn't like me using $site = "http://www.my-domain.com"; to locate the image files so I modified the script a wee bit to use $_SERVER['DOCUMENT_ROOT']; instead so now i'm using it like so: $user = $row['user']; $file = $_SERVER['DOCUMENT_ROOT']; $site = "http://www.my-domain.com"; if (@getimagesize($file . "/path-to-avatars/" . $user . "_10.jpg")) { $thumb = $site . "/path-to-avatars/" . $user . "_10.jpg"; } else { $thumb = $site . "/path-to-avatars/no_image.jpg"; } It's probably not the ideal solution but it works as expected. Thanks again for your help, fellas. Much appreciated.
  7. Thank you both for your prompt replies. Hi Maq - I went ahead and removed the @ and modified the query as suggested. After testing both locally and live everything appears to be ok on that end. Interestingly enough, I removed the @ from the getimagesize and it did indeed throw an error on my localhost. This error only displayed above each of the two users that didn't have an avatar. Warning: getimagesize(http://localhost/my-domain/path-to-avatars/trina_10.jpg) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:\wamp\www\my-domain\test.php on line 23 Line 23 of course is if(getimagesize...) Oddly enough it still works locally though as expected. The users without an avatar get the no_image.jpg and the users with have the correct image displayed. The above error isn't seen when testing live however and "No Image!" still persists. Here is the entire file, not much to it: <?php $dbc = mysql_connect('localhost', 'user', 'pass'); if(!$dbc) { exit ('<p>Unable to connect to the Database Server.</p>'); } mysql_select_db('dbname', $dbc); if (!mysql_select_db('dbname')) { exit('<p>Unable to locate the database.</p>'); } $result = mysql_query("SELECT * FROM database WHERE blah blah blah DESC LIMIT 0,5") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $user = $row['user']; $site = "http://www.my-domain.com"; if (getimagesize($site . "/path-to-avatars/" . $user . "_10.jpg")) { $thumb = $site . "/path-to-avatars/" . $user . "_10.jpg"; } else { $thumb = $site . "/path-to-avatars/no_image.jpg"; } echo "<li><a href=\"". $site ."/" . $user . "\"><img src=\"" . $thumb . "\"></a></li>"; } ?> I also triple-checked the image path references to be sure and everything there appears accurate. --- Hi AP81 - I'll have to try that as well once I get back tonight. For now it's off to work. Thank you both again for your time. It's very much appreciated.
  8. Hi folks, I'm back with another silly little problem. My php skills are laughable at best so please bear with me. Here is the deal. I have a very simple piece of code that really only does two things. First it checks to see if a user has uploaded an avatar on a remote box. If they have great, let's show it. If they haven't it should instead show a default "no image" avatar. Here is everything in a nutshell: $result = @mysql_query("SELECT * FROM database WHERE blah blah blah DESC LIMIT 0,5"); if(!$result) { exit('<p>Error performing query: ' . mysql_error() . '</p>'); } while ($row = mysql_fetch_array($result)) { $user = $row['user']; $site = "http://www.my-domain.com"; if (@getimagesize($site . "/path-to-avatars/" . $user . "_10.jpg")) { $thumb = $site . "/path-to-avatars/" . $user . "_10.jpg"; } else { $thumb = $site . "/path-to-avatars/no_image.jpg"; } echo "<li><a href=\"". $site ."/" . $user . "\"><img src=\"" . $thumb . "\"></a></li>"; } When I test this locally via WAMP it functions exactly as it should. If there is an avatar it shows and if there isn't the no_image.jpg shows instead. When I upload it the users that have an avatar continue to display correctly but those that don't instead get a "Not Found!" error and viewing the source shows why. It's still looking for the users avatar instead of switching to the no_image.jpg. Any thoughts or insight in to this quirky behavior would be greatly appreciated. Thanks for your time.
  9. Oops! I tried to edit my last post but the time limit expired. I just wanted to extend the coffee offer to you too pdkv2. Thank you both for taking the time to help me get this resolved. On to the next project!
  10. Thank you laffin! With the code you provided I was able to get it resolved and working as expected. If you'd like PM me your PayPal address so I can buy you a coffee. Thank you again, I appreciate it!
  11. Thank you pdkv2! I am very, very close to having this resolved now. Adding the above & worked perfectly for adding the missing character between the category and subcategory and it produces this: catalog.php?products=shirts&size=small&page=1 I have one more small problem though. When navigating through the pages each page clicked through adds an additional & to the beginning of the query_string (which I wrongfully assumed would have been removed automatically) so now it's producing this: catalog.php?&&&&&&&products=shirts&size=small&page=8 catalog.php?&&&&&&&&products=shirts&size=small&page=9 Any thoughts? Thank you again for your time, it's much appreciated!
  12. Hi All. I have a small problem I am hoping someone may be able to shed a little light on. I have a pagination script that works perfectly... for the most part. Everything works as expected when navigating through a main category page. The pagination links are output via: $this->return .= ($i == $this->current_page) ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[php_SELF]?$this->querystring&page=$i\">$i</a> "; The link(s) produced look like: catalog.php?products=shirts&page=5 However, when throwing a sub-category in to the mix to further refine the results the pagination links are incorrect/broken. It should produce a link like: catalog.php?products=shirts&size=small&page=5 but instead I get: catalog.php?products=shirtssize=small&page=5 Note the missing &. I have narrowed the problem down to how the var $querystring is called in to the pagination class which is: if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "page") $this->querystring .= $arg; } } if($_POST) { foreach($_POST as $key=>$val) { if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val"; } } That being said, my PHP skills are "laughable" at best so i'm not sure how to make this work for my needs. If more code is needed I can post it all but I believe (hope) that my problem is really only caused by the above code. Many thanks for your thoughts and time.
×
×
  • 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.