Jump to content

webbiegurrl

New Members
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

0 Neutral

About webbiegurrl

  • Rank
    Newbie
  1. I'm sure this kind of thing you can do in your sleep, but sadly I can't, but still want to get there. I really appreciate all your help and it pushed me to get this done. I almost gave up (& cried), but got it done and learned a lot along the way. Here is my final code - still had some snags that I had to sort out, but I did it. <?php $urlParts = explode('.', $_SERVER['HTTP_HOST']); $str = $urlParts[0]; $subdomain = preg_replace('#^https?://#', '', rtrim($str,'/')); $stmt = $pdo->prepare('SELECT * FROM images_tbl WHERE subdomain=? ORDER BY width ASC, height ASC, email'); $stmt->execute([$subdomain]); if($stmt->rowCount() != 0) { echo "<h3>Donated</h3>\n"; } $donations = []; foreach ($stmt as $row) { // if the donor doesn't exist yet, add their data if (!isset($donations[$row['width'].'x'.$row['height']][$row['email']])) $donations[$row['width'].'x'.$row['height']][$row['email']] = [ 'name' => $row['name'], 'url' => $row['url'], 'images' => [], ]; // append image $donations[$row['width'].'x'.$row['height']][$row['email']]['images'][] = $row['images_path']; } foreach ($donations as $dimensions => $dim_donations) { // show heading with dimensions echo "<br><br><h6>{$dimensions}</h6>\n"; foreach ($dim_donations as $email => $data) { $text = $data['url'] !== "your url" ? '<a href="' . $data['url'] . '" target="' . $target . '">' . $data[name] . '</a>' : "$data[name]"; // show donor's name or email address echo "<p>Donated by $text</p>\n"; foreach ($data as $images => $image) { if (is_array($image)) { foreach ($image as $code) { // list images echo '<img src="http://fan-a-tic.ca/common/' . $code . '" width="' . $dim_donations['width'] . '" height="' . $dim_donations['height'] . '">'; echo " \n"; } } } } } ?> Makes me feel like a million bucks when I can get things working the way I envision (even if it's with A LOT of help). Thanks again Jacques1!!!!
  2. Absolutely! I completely agree that this is much simpler (and definitely cleaner) than what I had. Thank you. I am stuck though with the script repeating the last value in every instance and I really can't see the problem. Here's what I have: <?php $urlParts = explode('.', $_SERVER['HTTP_HOST']); $str = $urlParts[0]; $subdomain = preg_replace('#^https?://#', '', rtrim($str,'/')); $stmt = $pdo->prepare('SELECT * FROM images_tbl WHERE subdomain=? ORDER BY width ASC, height ASC, email'); $stmt->execute([$subdomain]); if($stmt->rowCount() != 0) { echo "<h3>Donated</h3>"; } $donations = []; foreach ($stmt as $row) $donations[$row['width'].'x'.$row['height']][$row['email']][] = ['name' => $row['name'], 'url' => $row['url'], 'img' => $row['images_path']]; foreach ($donations as $dimensions => $dim_donations) { // show heading with dimensions echo "<br><br><h6>{$dimensions}</h6>\n"; foreach ($dim_donations as $email => $images) { $text = $row['url'] !== "your url" ? '<a href="' . $row['url'] . '" target="' . $target . '">' . $row[name] . '</a>' : ' . $row[name] . '; // show donor's name or email address echo "<p>Donated by $text</p>"; foreach ($images as $image) { // list images echo '<img src="http://mydomain.com/common/' . $row['images_path'] . '" width="' . $row['width'] . '" height="' . $row['height'] . '">'; } } } ?> I have been using print_r() to see what my array looks like (really trying to understand each step). So my $donations array looks like this Array ( [50x50] => Array ( [email@gmail.com] => Array ( [0] => Array ( [name] => Andrea [url] => http://domain.com [img] => donatedimages/subdomain/email@gmail.com/50x50/50x50a.jpg ) [1] => Array ( [name] => Andrea [url] => http://domain.com [img] => donatedimages/subdomain/email@gmail.com/50x50/50x50b.jpg ) ) ) [75x50] => Array ( [email@gmail.com] => Array ( [0] => Array ( [name] => Andrea [url] => http://domain.com [img] => donatedimages/subdomain/email@gmail.com/75x50/75x50a.jpg ) [1] => Array ( [name] => Andrea [url] => http://domain.com [img] => donatedimages/subdomain/email@gmail.com/75x50/75x50b.jpg ) ) ) etc... This all looks good to me. But under each dimension heading (which iterates properly) I'm getting the Donated by link followed by 3 graphics that are all 100x50c.jpg (the very last graphic), and if there is a different donator within the same dimension, it is the same exact link as the previous donator, not the new one. I'm really at a loss as print_r($images) shows me exactly what should be displayed but isn't. ... [1] => Array ( [name] => Andrea [url] => http://domain.com [img] => donatedimages/subdomain/email@gmail.com/50x50/50x50b.jpg ) [2] => Array ( [name] => Andrea [url] => http://domain.com [img] => donatedimages/subdomain/email@gmail.com/50x50/50x50c.jpg ) ) Donated by Andrea <---- this is the previous donator not the current one Array ( [0] => Array ( [name] => Barbara [url] => http://differentdomain.com [img] => donatedimages/subdomain/differentemail@gmail.com/50x50/5050-1.png ) ) I hope what I've explained makes sense.
  3. Jacques1, I must admit that when I first read your second submission, I was pretty ticked off by your bluntness. I mean I did state that I am just learning. I really felt like I was one simple tweak away with my existing script, but then you wanted me to put something else together entirely. I have been over and over your suggestion since reading it and have googled and really tried to figure it out how to setup the array - pretty sure I'm over complicating it. I want so desperately to learn php, you have no idea. I read once that you're either a coder and it all makes sense to you, or you're not. I really don't want that to be true and have persevered through the fog. The books I've read made sense to me while reading, but I haven't been able to put it into practice. Maybe this script will never behave the way I want. Can you point me in the direction of useful (up-to-date) tutorials for those who struggle to put all the pieces together? Sorry if you think I've wasted your time, as I can imagine that you have much more important things to do, but I really do want to learn. Thanks
  4. Thanks for answering Jacques1, but truthfully, I have no idea what you're talking about or where/how to implement it.
  5. First, please don't blast me for the ugly code, as I am still learning php and altering existing code is the easiest place to start. I hope to fix it up a bit once it's working properly. I want to display graphics in groups by size, but within that size also grouped by the donator. GRAPHIC SIZE Donated by Bob image image image Donated by Sue image image GRAPHIC SIZE The following code does successfully group by size, but just adds the new donator's codes in with the previous. <?php $urlParts = explode('.', $_SERVER['HTTP_HOST']); $str = $urlParts[0]; $subdomain = preg_replace('#^https?://#', '', rtrim($str,'/')); $stmt = $pdo->prepare('SELECT * FROM images_tbl WHERE subdomain=? ORDER BY width ASC, height ASC, email'); $stmt->execute([$subdomain]); if($stmt->rowCount() != 0) { echo "<h3>Donated</h3>"; } $current_size = null; $current_donator = null; while ($row = $stmt->fetch()) { $size = $row["width"].'x'.$row["height"]; $email = $row["email"]; if ($size != $current_size) { echo "<h6>{$size}</h6>\n"; $url = $row["url"]; $name = $row["name"]; $text = $row["url"] !== "your url" ? '<a href="' . $url . '" target="' . $target . '">' . $name . '</a>' : $name; if ($email != $current_donator) { echo "<p>Donated by $text</p>"; $current_donator = $email; } $current_size = $size; } if ($row["url"] !== "your url") { ?> <a href="<?=$row["url"]?>" target="<?=$target?>"><img src="DOMAIN/<?=$row["images_path"]?>" width="<?=$row["width"]?>" height="<?=$row["height"]?>" title="donated by <?=$row["name"]?>"></a> <?php } else { ?> <img src="DOMAIN/<?=$row["images_path"]?>" width="<?=$row["width"]?>" height="<?=$row["height"]?>" title="donated by <?=$row["name"]?>"> <?php } } ?>
  6. Not exactly sure how to do that, though I do understand what you mean. Even though the query works, it seems very crude next to the existing code, is there anyway of using what's already there to add what I need? Here's the full page <? require 'config.php'; require_once( 'mod_errorlogs.php' ); require_once( 'mod_owned.php' ); require_once( 'mod_members.php' ); require_once( 'mod_settings.php' ); // function to clean data if( !function_exists( 'clean' ) ) { function clean( $data ) { $data = trim( htmlentities( strip_tags( $data ), ENT_QUOTES ) ); if( get_magic_quotes_gpc() ) $data = stripslashes( $data ); $data = addslashes( $data ); return $data; } } // get listing info and member type $info = get_listing_info( $listing ); $member_type = ( $info['listingtype'] == 'fanlisting' ) ? 'fans' : 'members'; // explode the fields for sorting and make sure there are no whitespace $sortarray = explode( ',', $info['sort'] ); foreach( $sortarray as $i => $s ) $sortarray[$i] = trim( $s ); // what sorting fields have been selected already by the visitor? // obtain from $_GET array $set = 0; $selected = array(); // what have we selected? $sortfield = $sortarray[$set]; // what field are we currently sorting? while( isset( $sortarray[$set] ) && isset( $_GET[$sortarray[$set]] ) ) { // while the user has selected a value to sort with $selected[$sortarray[$set]] = $_GET[$sortarray[$set]]; if( $selected[$sortarray[$set]] == 'all' ) $selected[$sortarray[$set]] = '%'; $set++; if( isset( $sortarray[$set] ) ) $sortfield = $sortarray[$set]; } //$set--; $sorters = get_member_sorter( $listing, $set, $selected ); // are we still going to show the sorting? if( count( $sortarray ) == $set ) // this is the last? return; // create list URL $list_url = $info['listpage']; $connector = '?'; if( substr_count( $list_url, '?' ) > 0 ) if( $info['dropdown'] == 1 ) $connector = '&'; else $connector = '&'; // get anything that's already in $selected and put it in the URL $in_url = array(); foreach( $selected as $field => $value ) { $field = clean( $field ); $value = clean( $value ); if( in_array( $field, $in_url ) ) continue; $list_url .= "$connector$field=$value"; if( $info['dropdown'] == 1 ) $connector = '&'; else $connector = '&'; $in_url[] = $field; } // if owner selected the dropdown method if( $info['dropdown'] == 1 ) { ?> <script type="text/javascript"> <!-- function change( form ) { var dropDown = form.elements[0]; var myIndex = dropDown.selectedIndex; if( dropDown.options[myIndex].value != "0" ) { window.open( "<?php echo $list_url . $connector . $sortfield ?>=" + dropDown.options[myIndex].value, target = "_self" ); } } // end --> </script> <form method="get" action="<?php echo $list_url ?>" class="show_sort_form"> <p> <select name="<?php echo $sortfield ?>" onchange="change( this.form );"> <option value="0"> Select sort option</option> <option value="all"> All <?php echo $member_type ?></option> <?php foreach( $sorters as $sort ) if( $sort == '' ) echo '<option value="none"> None given </option>'; else echo '<option value="' . $sort . '"> ' . $sort . '</option>'; ?> </select> </p> </form> <?php } else { ?> <p class="show_members_showing_what">from <?=count($sorters) ?> Countries</p> <p class="center"><a href="">Sorted by Country</a> | <a href="<?=$siteurl?>/sort.php?country=all">Full List</a></p> <div class="flaglist"> <? foreach( $sorters as $sortvalue ) $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT country, COUNT(*) FROM $table GROUP BY country') as $row) { if( $sortvalue == '' ) echo '<li> <a href="' . $list_url . $connector . $sortfield . '=none">None given</a> </li>'; else if ($row['COUNT(*)'] != "1") echo '<a href="' . $list_url . $connector . $sortfield . '=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a> ' . $row['COUNT(*)'] . ' fans<br>'; else echo '<a href="' . $list_url . $connector . $sortfield . '=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a> ' . $row['COUNT(*)'] . ' fan<br>'; } } ?> </div>
  7. Please be kind as I am simply modifying an existing script to suit my needs and I am still just learning PHP. I have this code foreach( $sorters as $sortvalue ) if( $sortvalue == '' ) echo '<li> <a href="' . $list_url . $connector . $sortfield . '=none">None given</a> </li>'; else echo '<li> <a href="' . $list_url . $connector . $sortfield . '=' . $sortvalue . '">' . $sortvalue . '</a> </li>'; echo '</ul>'; which lists the names of the countries that members live in. I have modified this to show the country's flag instead of the name. foreach( $sorters as $sortvalue ) if( $sortvalue == '' ) echo '<li> <a href="' . $list_url . $connector . $sortfield . '=none">None given</a> </li>'; else echo '<a href="' . $list_url . $connector . $sortfield . '=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a><br>'; This works very nicely, but I also wanted to display the number of members for each country, so I further modified the code and got this foreach( $sorters as $sortvalue ) /* $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT country, COUNT(*) FROM $table GROUP BY country') as $row) { */ if( $sortvalue == '' ) echo '<li> <a href="' . $list_url . $connector . $sortfield . '=none">None given</a> </li>'; else if ($row['COUNT(*)'] != "1") echo '<a href="' . $list_url . $connector . $sortfield . '=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a> ' . $row['COUNT(*)'] . ' fans<br>'; else echo '<a href="' . $list_url . $connector . $sortfield . '=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a> ' . $row['COUNT(*)'] . ' fan<br>'; } The section that is currently commented out will give the correct number, but makes all the flags the same. Or with it commented out, the flags are correct, but (obviously) no values. I can't seem to trial & error my way through getting both working. Can someone tell me what I'm doing wrong please?
  8. Just popping by to say hello! I love using PHP but am mostly just a dabbler who likes to figure out how to modify existing scripts. I would LOVE to know more about it and will most likely learn a lot by checking out all the posts here. See you around the boards
×
×
  • 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.