justin7410 Posted May 5, 2013 Share Posted May 5, 2013 hey guys, since i am so new to php and programming , i am having extreme difficulty creating a function from scratch. i understand functions if i am reading one or if watching a tutorial , but trying to create one based one what i need is proving to be a bit confusing for me. PURPOSE the purpose of the function is to grab an id from my user database , and convert that ID to an md5. i already have a while loop that is grabbing all the content from my database and then extracting it to the page. i then want to display the image id in a loops surrounded by <img> tags to show each individual persons image with the correct id from the DB. so the link would be looking like this if you were to inspect the element <a><img src=http://s3.amazonaws.com/fast-network/photo2/c24c98bb1b2e9aac64cab553d94a22d7_.jpg" width="101" height="150"></a> if you were to look in text editor it would be like <?php while ($row = mysql_fetch_assoc($content)) { extract($row); echo '<li>'; echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src="http://s3.amazonaws.com/fast-network/photos/c4ca4238a0b923820dcc509a6f75849b.jpg" width="101" height="150"></a></div>'; echo '<div class="member_about">'; echo '<div class="member_about_text">'; echo '<h1><a href="profile.php?member=' .$imdb_title . '&memberid=' .$id .'">' . $member_title . ' (2013)</a></h1>'; echo '<div class="c">Class: ' .$class_year . '</div>'; echo 'Courses:' . $_courses_taken . '<br>'; echo 'Views: <span>194526</span> (<span>176</span> votes)<br>'; echo 'Votes:' .$votes .' <br>'; echo '</div>'; echo '<div class="about_rete">'; echo '<div class="vote">'; echo '<div id="Mark">'; echo '<div id="Maro">Rating: $rating . ' </span></div>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</li>'; } ?> HERE IS WHERE I WANT TO ADD THE FUNCTION echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src="http://s3.amazonaws.com/fast-network/photos/c4ca4238a0b923820dcc509a6f75849b.jpg" width="101" height="150"></a></div>'; INSTEAD IT WOULD LOOK LIKE THIS echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src=" http://s3.amazonaws.com/fast-network/photos/display_member_image($id).jpg " width="101" height="150"></a></div>'; ultimately i would like some feedback as to how to best approach creating this function to what i need it to do .. i will be using this function anywhere i want the image to be shown. Quote Link to comment Share on other sites More sharing options...
trq Posted May 5, 2013 Share Posted May 5, 2013 Functions are simple, what part exactly do you not understand? Also, you don't need a custom function for this. md5 already exists and does what you want already. Quote Link to comment Share on other sites More sharing options...
justin7410 Posted May 5, 2013 Author Share Posted May 5, 2013 (edited) the part i guess i am not quite clear on is as to where what variables need to be stored. function load_content_images($id) { $id = md5($id); } i think i am on the right track , but i am not sure if the $id that is being inputted will be the same $id that is being sent from the extract() on my page listing all members. Edited May 5, 2013 by justin7410 Quote Link to comment Share on other sites More sharing options...
trq Posted May 5, 2013 Share Posted May 5, 2013 If all your function does is md5 the variable your passing to it, then it is useless, that is exactly what md5() already does, just use that. but i am not sure if the $id that is being inputted will be the same $id that is being sent from the extract() on my page listing all members. You pass variables into functions when you call them so you have complete control about the data they operate on. Quote Link to comment Share on other sites More sharing options...
Solution justin7410 Posted May 5, 2013 Author Solution Share Posted May 5, 2013 yes but i guess i figured out the way to do this , i was simply over complicating things worrying about the query, but the query is already set when i extract anyway . thanks for the input tho good sir. much appreciated. just for answer purposes function load_content_images($id) { $id = md5($id); return 'http://s3.amazonaws.com/fast-network/photos/' .$id .'.jpg'; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.