lordphate Posted June 21, 2007 Share Posted June 21, 2007 okay what i'm trying to do is make something from the mysql database work as a image function contest_extract_answers($answers_code){ $answers = explode("|",trim($answers_code,"|")); array_unshift($answers,""); unset($answers[0]); return $answers; }//contest_extract_answers $answers will be a path to the pictures minus the domain.com/photos So i tried making it function contest_extract_answers($answers_code){ $answers = explode("|",trim($answers_code,"|")); array_unshift($answers,""); unset($answers[0]); return "<img src='http://www.domain.com/photos/".$answers.">"; }//contest_extract_answers but this causes the "photo" to be http://www.domain.com/photos/Array How do i turn the "Array" into the /path/to/photo.jpg Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/ Share on other sites More sharing options...
sasa Posted June 21, 2007 Share Posted June 21, 2007 try function contest_extract_answers($answers_code){ $answers = explode("|",trim($answers_code,"|")); array_unshift($answers,""); unset($answers[0]); $out =''; foreach($answera as $v) {$out .= <img src='http://www.domain.com/photos/".$v.">";}; //return "<img src='http://www.domain.com/photos/".$answers.">"; return $out; } Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/#findComment-279061 Share on other sites More sharing options...
lordphate Posted June 21, 2007 Author Share Posted June 21, 2007 Warning: Invalid argument supplied for foreach() in C:\wamp\www\paul\modules\contest.php on line 259 Warning: array_keys() [function.array-keys]: The first argument should be an array in C:\wamp\www\paul\modules\contest.php on line 61 Warning: Invalid argument supplied for foreach() in C:\wamp\www\paul\modules\contest.php on line 100 58 $card["author"] = $GLOBALS["Network"]->card($res["mem_id"]); 59 $card["question"] = $res["question"]; 60 $card["answers"] = contest_extract_answers($res["answers"]); 61 $card["stats"] = contest_stats($res["con_id"],array_keys($card["answers"])); 62 $card["approved"] = $res["approved"]; 99 $stats["votes"] = array(); 100 foreach($answers as $a){ 101 $stats["votes"][$a] = @round($votes[$a]/$stats["total"],2) * 100; 102 }//foreach 258 $out =''; 259 foreach($answera as $v) {$out .= "<img src='http://www.paul.com/photos/".$v."'>";}; 260 //return "<img src='http://www.domain.com/photos/".$answers.">"; 261 return $out; Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/#findComment-279065 Share on other sites More sharing options...
sasa Posted June 21, 2007 Share Posted June 21, 2007 sorry i made mistake 'foreach($answers ...' not '$answera' Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/#findComment-279069 Share on other sites More sharing options...
lordphate Posted June 21, 2007 Author Share Posted June 21, 2007 Yeah i noticed that, but i'm still getting Warning: array_keys() [function.array-keys]: The first argument should be an array in C:\wamp\www\paul\modules\contest.php on line 61 Warning: Invalid argument supplied for foreach() in C:\wamp\www\paul\modules\contest.php on line 100 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\paul\modules\contest.php:61) in C:\wamp\www\paul\functions\build_functions.php on line 120 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\paul\modules\contest.php:61) in C:\wamp\www\paul\functions\build_functions.php on line 121 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\paul\modules\contest.php:61) in C:\wamp\www\paul\functions\build_functions.php on line 122 Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\paul\modules\contest.php:61) in C:\wamp\www\paul\functions\build_functions.php on line 123 Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/#findComment-279071 Share on other sites More sharing options...
teng84 Posted June 21, 2007 Share Posted June 21, 2007 contest_extract_answers($answers_code) $answers_code == array??? that suppose to an array and check if that a multi or not that should be a single array Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/#findComment-279073 Share on other sites More sharing options...
redarrow Posted June 21, 2007 Share Posted June 21, 2007 example only. always valadate ok. <?php $pic_array=array("http://www.google.co.uk/intl/en_uk/images/logo.gif"); $x=implode(' ',$pic_array); if(eregi("^(http://www)\.[a-z0-9\_\-]{1,50}\.[a-z]{0,3}\.[a-z]{0,3}\/[a-z\_-]{0,50}\/[a-z\_-]{0,50}\/[a-z\_-]{0,50}\/[a-z]{0,50}\.(jpg|gif|png)",$x)){ echo"<img src'$x'></img>"; }else{ echo "sorry pic does not exist"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56501-array/#findComment-279086 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.