runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 function get_id ( $id ) { global $db; $query = "SELECT `ID` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); return $row->ID; } else { return FALSE; } } Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407117 Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 ok can any 1 help me with this lil bit $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`= $pID' ; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' $pID. $row['ext']. '" />'; } }else{ echo 'Error: Image not found.'; } how can i right this properly $pID. $row['ext']. '" />'; Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407133 Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 Once again, why are you querying the database for the extension? There are only a limited number of possible extensions and really, there is no need wasting resources querying for it. As for how to write your line properly.... echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. $row['ext'] . '" />'; Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407227 Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 its still not outputting an image... any idea why.. i thought i had it by gtting user id and then looking up extension file to the id so i.jpg and then echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. $row['ext'] . '" />'; should show it Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407238 Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 i dont get why its not working surly it should get . $pID. $row['ext'] or 1.jpeg Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407302 Share on other sites More sharing options...
runnerjp Posted December 5, 2007 Author Share Posted December 5, 2007 ok $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`='$pid; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; }*/ should do it if 2 things 1.`user_id`='$pid; how would i display this correctly? 2. echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />'; is this correct way of showin id.ext?? or 1.jpg Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407308 Share on other sites More sharing options...
helraizer Posted December 6, 2007 Share Posted December 6, 2007 ok $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`='$pid; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; }*/ should do it if 2 things 1.`user_id`='$pid; how would i display this correctly? 2. echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />'; is this correct way of showin id.ext?? or 1.jpg If I am correct in thinking, the URL you should use single quotes for the "." as '.' because at the moment you've broken the URL up. echo '<img src="http://www.runningprofiles.com/members/images/' . $pID . '.' .$row['ext'] . '" />' Sam Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407424 Share on other sites More sharing options...
SirChick Posted December 6, 2007 Share Posted December 6, 2007 What i would of done is if the picture is always in the same place on the screen.... just echo the username ontop of the image using absolute position in div tags... so it looks like its part of the picture when infact its actually "above the image" Plus if its using a $Username.. when ever the name is changd it will change according.. how ever this won't work if the picture is not always in the same place. Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407427 Share on other sites More sharing options...
trq Posted December 6, 2007 Share Posted December 6, 2007 is this correct way of showin id.ext?? or 1.jpg Where in your code do you toell it to display 1.jpg if no record is found? You don't! This thread is getting out of hand. You seriously need to learn the basics and come back to this idea in a few months when you get it. Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407487 Share on other sites More sharing options...
runnerjp Posted December 6, 2007 Author Share Posted December 6, 2007 <?$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=$pid; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' . $pID . '.' .$row['ext'] . '" />' } }else{ echo 'Error: Image not found.'; } ?> but thorpe i know how to display 1.jpg if the image insnt found i will add that later.. my point is that i cant get the users image first!! echo '<img src="http://www.runningprofiles.com/members/images/' . $pID . '.' .$row['ext'] . '" />'... has a nexpected T_STRING Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407808 Share on other sites More sharing options...
runnerjp Posted December 6, 2007 Author Share Posted December 6, 2007 $sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id']; $q = mysql_query($sql); if($q){ $row = mysql_fetch_array($q); echo 'emma'; if(!empty($row)){ echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. $row['ext'] . '" />'; } }else{ echo 'Error: Image not found.'; } fixed the error on my own lol showing i can fix some errors lol but not one not displaying the image :S Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-407842 Share on other sites More sharing options...
runnerjp Posted December 6, 2007 Author Share Posted December 6, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408073 Share on other sites More sharing options...
trq Posted December 6, 2007 Share Posted December 6, 2007 Seriously, I think this thread has gone on long enough. If you can't fix your problems with 100+ replies to your thread, there are bigger issues. Firstly, try some debugging. Where the hell does $pID come from? What does it contain (echo it to find out)? Does what it contains relate to an actual image name? I'll say it again, I see no reason for you to be using a database in this situation at all. However, you seam to have completely ignored this (and I would assume alot of other) good advice. Seams to me you don't have a good grasp of the basics yet. Maybe a read of the free book in my signiture could get you heading down the right path? Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408077 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 im doing this with tinkering ect.. i do have a problem $query = "SELECT ext FROM user_image WHERE user_id='$user_id' LIMIT 1"; it give me #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = "SELECT ext FROM user_image WHERE user_id='$user_id' LIMIT 1"' at line 1 can any 1 enlighten me on this please? oh and thrope... if there are 2 images by the user in the folder e.g 1.jpg 1.gif then the script will show more then 1 ? Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408712 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 ok took every ones advise and i suppose i shudda sat down and pulled it apart myself but i got it working thanks guys at last i can close this thread lol Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408787 Share on other sites More sharing options...
PHP_PhREEEk Posted December 7, 2007 Share Posted December 7, 2007 NO WAY!!! heheheh grats everyone!! beers all around! = ^D PhREEEk Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408791 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 i do have anouther weeee problem the code always trys to find the users id with the ext.... if(isset($q)){ while ($row = mysql_fetch_array($q)) { echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext']. "' />"; } }else{ echo "<img src='http://www.runningprofiles.com/members/images/pic.jpg />"; } it wont echo the pic.jpg if there are no files...how comes? Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408874 Share on other sites More sharing options...
adam291086 Posted December 7, 2007 Share Posted December 7, 2007 because there is no information in the array left to echo. Therefore it goes to your else statement. Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408878 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 humm so how would i go about showing the image if no image iss found ?? Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408879 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 need a default image to be shown Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408929 Share on other sites More sharing options...
adam291086 Posted December 7, 2007 Share Posted December 7, 2007 what you have already should do what you want. While there is information from the database echo there picture else echo "<img src='http://www.runningprofiles.com/members/images/pic.jpg />"; That should work. Do you have a picture called pic.jpg? Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408930 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 i do but every time it just adds eg 4.jpg if users name is 4 even if there is no file :S Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408962 Share on other sites More sharing options...
roopurt18 Posted December 7, 2007 Share Posted December 7, 2007 I suspect that $q will always be set, since it is capturing the value of mysql_query(). You should run a test for: if(file_exists(...)) Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408971 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 like $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$username' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q){ $row = mysql_fetch_array($q); if(file_exists($row)) echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; }{ else echo 'Error: Image not found.'; } Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-408982 Share on other sites More sharing options...
runnerjp Posted December 7, 2007 Author Share Posted December 7, 2007 ok this is wired had it all working now wont display the echo or an image $sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$username' LIMIT 1"; $q = mysql_query($sql) or die("Error running query:".mysql_error()); if($q){ $row = mysql_fetch_array($q); if(!empty($row)){ echo "<img src='http://www.runningprofiles.com/members/images/". $pid . "." . $row['ext'] . "' />"; } }else{ echo 'Error: Image not found.'; } no errors just doent display anything...a blank page yet it did afew minutes ago :S Link to comment https://forums.phpfreaks.com/topic/79136-solved-adding-username-to-image/page/5/#findComment-409022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.