homepage Welcome to WebmasterWorld Guest from 54.205.189.156
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Problem in foreach loop with unserialized content
unserialzed
canabatz




msg:4515835
 12:14 pm on Nov 5, 2012 (gmt 0)

Hi,

i got problem in foreach loop, the code is stuck on first loop.


any one see any problem in the code?
im stuck on it for a day now.

thanks !

function get_rss()
{
global $catArray, $yesterday, $date;

$rss = mysql_query("SELECT id, cat, tcat, title, pic FROM portal_coverages WHERE v = 1 AND date BETWEEN ('" . $yesterday . "') AND ('" . $date . "')ORDER BY id DESC");
$resultp = array();

while($row = mysql_fetch_object($rss))
{
$resultp[$row -> cat][$row -> tcat] = $resultp[$row -> cat][$row -> tcat] . "
<tr>
<td><p style='color:#F91010;'>" . $catArray[$row -> cat . "," . $row -> tcat] . "</p></td>
<td><img src='http://dossinet.me/" . $row -> pic . "' width='50' height='50' /></td>
<td>" . $row -> title . "</td>
<td><a href='http://dossinet.me/view," . $row -> id . ".html'>&#1511;&#1497;&#1513;&#1493;&#1512; </a></td>
</tr>
";
}

return $resultp;
}


include("rss/mail_class.php");

$kk=1;
$query = mysql_query("SELECT rss_id, user_id FROM `portal_rss`")or die(mysql_error());
$get_rss = get_rss();

while($row = mysql_fetch_object($query))
{
$rss_id = unserialize($row -> rss_id);

$kk++;
foreach($rss_id as $key)
{
$x = explode(',', $key);

if(!empty($get_rss[$x[0]][$x[1]]))
{
$title .= $catArray[$key] . ', ';
$result .= $get_rss[$x[0]][$x[1]];
}
}

if(!empty($result))
{
$query = mysql_query("SELECT * FROM `user` WHERE `userid` ='" . $row -> user_id . "'")or die(mysql_error());
$rowz = mysql_fetch_array($query);

$user['name'] = $rowz['username'];
$user['email'] = $rowz['email'];
echo $user['email'];
$params = array(
'file' => 'rss',
'subject' => "&#1506;&#1491;&#1499;&#1493;&#1504;&#1497; &#1511;&#1496;&#1490;&#1493;&#1512;&#1497;&#1492; - " . $title,
'from_name' => "&#1506;&#1491;&#1499;&#1493;&#1504;&#1497; &#1511;&#1496;&#1490;&#1493;&#1512;&#1497;&#1492; ",
'vars' => array('cat' => $title, 'post' => $result, 'name' => $user['name']),
);

Mail::To($user['email']);
Mail::set_mail($params, true);
Mail::send_mail($params);
}
}

 

lostdreamer




msg:4515841
 1:02 pm on Nov 5, 2012 (gmt 0)

I dont know for sure (indenting here is not so nice) but I believe you are overwriting the "$query" variable inside the query, thus; when looping over the first $query object the second time, it's not the original one anymore.

try changing:

$query = mysql_query("SELECT * FROM `user` WHERE `userid` ='" . $row -> user_id . "'")or die(mysql_error());
$rowz = mysql_fetch_array($query);


to


$query2 = mysql_query("SELECT * FROM `user` WHERE `userid` ='" . $row -> user_id . "'")or die(mysql_error());
$rowz = mysql_fetch_array($query2);


To test my hypothesis ;)

canabatz




msg:4516047
 9:02 pm on Nov 5, 2012 (gmt 0)

Thanks, that was the problem!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved