pietbez Posted January 15, 2009 Share Posted January 15, 2009 i am having trouble to format my echo output. all the info that i need is there, it is just not in the right format for my flash file to read. $res = ms_select("title, (SELECT count(*) FROM `items` WHERE items.category = categories.id) , (SELECT thumb_pic_path FROM `items` WHERE items.category = categories.id ORDER BY votes DESC LIMIT 0,1)", "categories", "active = 1" ); while($rec = mysql_fetch_row($res)){ echo "&cat=" . $rec[0] . "&pic=" . $rec[2]; } ?> my output looks like this &cat=cat1&pic=pic1.jpg&cat=cat2&pic=pic2.jpg&cat=cat3&pic=pic3.jpg but i need it to look like this &cat=cat1|cat2|cat3|&pic=pic1|pic2|pic3| please help. i have been stuck on this for the last 5 hours! Link to comment https://forums.phpfreaks.com/topic/140890-solved-trouble-formating-echo/ Share on other sites More sharing options...
kenrbnsn Posted January 15, 2009 Share Posted January 15, 2009 You're going to have to use 2 temporary arrays to store the results before echoing them: <?php $res = ms_select("title, (SELECT count(*) FROM `items` WHERE items.category = categories.id) , (SELECT thumb_pic_path FROM `items` WHERE items.category = categories.id ORDER BY votes DESC LIMIT 0,1)", "categories", "active = 1" ); $cat = array(); $pic = array(); while($rec = mysql_fetch_row($res)){ $cat[] = $rec[0]; $pic[] = $rec[2]; } echo "&cat=" . implode('|',$cat) . "|&pic=" . implode('|',$pic) . '|'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/140890-solved-trouble-formating-echo/#findComment-737434 Share on other sites More sharing options...
pietbez Posted January 15, 2009 Author Share Posted January 15, 2009 thanks ken, you made one dude very hapy tonight Link to comment https://forums.phpfreaks.com/topic/140890-solved-trouble-formating-echo/#findComment-737448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.