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 Quote Link to comment 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? Quote Link to comment 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) Quote Link to comment 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?? Quote Link to comment 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() Quote Link to comment 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? Quote Link to comment 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; } Quote Link to comment 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. Quote Link to comment 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 ? Quote Link to comment 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 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.