webtuto Posted August 1, 2009 Share Posted August 1, 2009 hi i have a code that INSERT information in a database $sql = mysql_query("INSERT INTO `docs` (`artist` ,`genre` ,`link`)VALUES ('".addslashes($this->show_caption($caption))."', 'hiphop' ,'".addslashes($this->show_href($href))."')"); $this->show_caption($caption) and $this->show_href($href) have at least 10 values so i want every re sult to be on an ID like this +id + genre + link +1 + first value of caption + first value of href +2 + second value of caption + first value of href i need LOOP using foreach or while or something , i dont know exactely what to do thanks for the help Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/ Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 Does $this->show_caption() return an array of results? Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888480 Share on other sites More sharing options...
webtuto Posted August 1, 2009 Author Share Posted August 1, 2009 yes it return alot of r esults also $this->show_href($href) Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888482 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 Does $this->show_caption() return an array of results? Does it return an array?? Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888486 Share on other sites More sharing options...
webtuto Posted August 1, 2009 Author Share Posted August 1, 2009 i dont think so im not sure on the result shown on the page , it return links (its a crawler) and iwant to put these links in the database , everyone on his own ID i dont think its an array on the whole page there is no ARRAY() Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888488 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 can you show the code for the show_caption() method? Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888490 Share on other sites More sharing options...
webtuto Posted August 1, 2009 Author Share Posted August 1, 2009 yeah its a function function show_caption($mode) { $this->get_links(); $bb=""; for ($i=1;$i<=count($this->caption);$i++) { if ($mode==0) echo $this->caption[$i]."\n<br>\n"; else echo $i."-->".$this->caption[$i]."\n<br>\n"; $bb .= $this->caption[$i]; } return $bb; } Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888491 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 You'd be better off returning an array that you can iterate over and add to the database, than a long string of data. If you want to make several entries into your db you'd first have to separate your string to iterate over that. Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888496 Share on other sites More sharing options...
webtuto Posted August 1, 2009 Author Share Posted August 1, 2009 well idont know how to do that can you edit it yourself ? Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888497 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 You could just return $this->caption() in the method. The same with $this->href(). Assign them to a new array. <?php$captions = $this->show_caption($caption); //(where the return is return $this->caption())$hrefs = $this->show_href($href); //(where the return is also the array of href's)for($i=0, $i<count($captions());$i++) {$sql = mysql_query("INSERT INTO `docs` (`artist` ,`genre` ,`link`)VALUES ('".addslashes($captions[$i])."', 'hiphop' ,'".$hrefs[$i])."')");} the code for the method... <?phpfunction show_caption($mode){$this->get_links();$bb="";for ($i=1;$i<=count($this->caption);$i++){ if ($mode==0) echo $this->caption[$i]."\n<br>\n"; else echo $i."-->".$this->caption[$i]."\n<br>\n";}return $this->caption;} You'll have to edit the show_href() method as well Link to comment https://forums.phpfreaks.com/topic/168434-looping-problem-help/#findComment-888498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.