Jump to content

[SOLVED] trouble formating echo


pietbez

Recommended Posts

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

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

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.