Jump to content

looping problem -help-


webtuto

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

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