Jump to content

Help creating a working function


justin7410
Go to solution Solved by justin7410,

Recommended Posts

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

 

 

 

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.

 

Link to comment
Share on other sites

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 by justin7410
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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';
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.