selenin Posted June 8, 2010 Share Posted June 8, 2010 Hello, I try to make some loops, here is my code: $sourcesnot = mysql_query("SELECT megavideo, novamov, videoweed, movshare, stagevu FROM pm_player_sources WHERE uniq_id = '".$uniqid."'"); //$row4 = mysql_fetch_array( $sourcesnot ); while($row5 = mysql_fetch_array($sourcesnot)) { $id = $row5; foreach ($id as $k => $v ) { if ($v > 0){ //unset($sources[$v]); var_dump($v); } } } and that's what I get: string(1) "4" string(1) "4" string(1) "6" string(1) "6" but I need only one 4 and one 6 like it is in my database, I think I made a wrong loop and has somebody an idea how to collect them to make an unset() function Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/ Share on other sites More sharing options...
kenrbnsn Posted June 8, 2010 Share Posted June 8, 2010 If you change your script to be: <?php $sourcesnot = mysql_query("SELECT megavideo, novamov, videoweed, movshare, stagevu FROM pm_player_sources WHERE uniq_id = '".$uniqid."'"); //$row4 = mysql_fetch_array( $sourcesnot ); while($row5 = mysql_fetch_array($sourcesnot)) { echo '<pre>' . print_r($row5,true) . '</pre>' } ?> You will see that the function mysql_fetch_array returns each field twice. Use the function mysql_fetch_assoc instead. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069594 Share on other sites More sharing options...
selenin Posted June 8, 2010 Author Share Posted June 8, 2010 Yuppi, thanks a lot kenrbnsn, so the loops were right only wrong function, now is there a way to collect these values to make with them unset() Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069599 Share on other sites More sharing options...
kenrbnsn Posted June 8, 2010 Share Posted June 8, 2010 This question is there a way to collect these values to make with them unset() is unclear. Please explain better. Ken Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069603 Share on other sites More sharing options...
selenin Posted June 8, 2010 Author Share Posted June 8, 2010 My problem is I'm very bad with arrays, just started with. So here now I get 4 and 6 the others are 0, now I want to unset() 4 and 6 more below in the script from the players because the players (keys) 4 and 6 are already used. I thought I make now a new array and unset them with a foreach, I did like that $arr = array(); $arr[] = $v; but then I get two arrays like array(1) { [0]=> string(1) "4" } array(1) { [0]=> string(1) "6" } I don't know if it will work just try it that way Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069616 Share on other sites More sharing options...
ignace Posted June 8, 2010 Share Posted June 8, 2010 What is your intention with unset? To delete the rows from your database? Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069649 Share on other sites More sharing options...
selenin Posted June 8, 2010 Author Share Posted June 8, 2010 I have another array and I want to unset() these keys, that works, testet with one number, but my problem now is I don't get an array $sourcesnot = mysql_query("SELECT megavideo, novamov, videoweed, movshare, stagevu FROM pm_player_sources WHERE uniq_id = '".$uniqid."'"); //$row4 = mysql_fetch_array( $sourcesnot ); while($row5 = mysql_fetch_assoc($sourcesnot)) { $id = $row5; foreach ($id as $k => $v ) { if ($v > 0){ //$sourcenot = '['.$v.']'; //var_dump($v); //unset($sources[$v]); $arr = array($v); //$arr[] = $v; var_dump($arr); } } } and I get this array(1) { [0]=> string(1) "4" } array(1) { [0]=> string(1) "6" } but I always need only one array Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069658 Share on other sites More sharing options...
kenrbnsn Posted June 8, 2010 Share Posted June 8, 2010 Try: <?php $sourcesnot = mysql_query("SELECT megavideo, novamov, videoweed, movshare, stagevu FROM pm_player_sources WHERE uniq_id = '".$uniqid."'"); $arr = array(); while($row5 = mysql_fetch_assoc($sourcesnot)) { foreach ($row5 as $k => $v ) { if ($v > 0){ $arr[] = $v; } } } echo '<pre>' . print_r($arr,true) . '</pre>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069671 Share on other sites More sharing options...
selenin Posted June 8, 2010 Author Share Posted June 8, 2010 Thanks a lot kenrbnsn, I was so close and now the whole thing is working with unset(), unbelievable Quote Link to comment https://forums.phpfreaks.com/topic/204205-something-wrong-with-my-loops/#findComment-1069682 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.