CanMan2004 Posted January 25, 2007 Share Posted January 25, 2007 Hi allI have quite a long query, it looks like[code]if (type0 == '11') { $sql1 = mysql_query("SELECT * FROM items WHERE uid = '".$uid0."'")or die(mysql_error()); } else { $sql1 = mysql_query("SELECT * FROM WHERE uid = '".$uid0."'")or die(mysql_error()); } while($row1 = mysql_fetch_array($sql1)) { $title1 = $row1['title']; $subtitle1 = $row1['subtitle']; } $sql2a = mysql_query("SELECT * FROM subcats WHERE uid = '".$subcats0."'")or die(mysql_error()); while($row2a = mysql_fetch_array($sql2a)) { $value2a = $row2a['value']; } $sql2b = mysql_query("SELECT * FROM product WHERE uid = '".$productcats0."'")or die(mysql_error()); while($row2b = mysql_fetch_array($sql2b)) { $value2b = $row2b['value']; } while($row4 = mysql_fetch_array($sql4)) { $qty4 = $row4['qty']; } print $value2a.' - '.$value2b.' <> '; } [/code]This outputs something likeIPODS - Apple Nano <> Laptops - VAIO Desktop I want to encapsulate the above queries and use it as a variable, so I can define the above as$description =So that I can then pass this to another page.Does this make sense?Can anyone helpThanksEd Link to comment https://forums.phpfreaks.com/topic/35697-query-question/ Share on other sites More sharing options...
CanMan2004 Posted January 26, 2007 Author Share Posted January 26, 2007 Can anyone help me with this?ThanksEd Link to comment https://forums.phpfreaks.com/topic/35697-query-question/#findComment-169575 Share on other sites More sharing options...
Cep Posted January 26, 2007 Share Posted January 26, 2007 It looks like your building a string (your codes not very clear) so why not say before anything is done,[code=php:0]$description = "";[/code]Then for your data just append the string each time you add something new (or loop through),[code=php:0]$description = $description.$value2a.' - '.$value2b.' <> ';[/code] Link to comment https://forums.phpfreaks.com/topic/35697-query-question/#findComment-169576 Share on other sites More sharing options...
CanMan2004 Posted January 26, 2007 Author Share Posted January 26, 2007 Basically because it is pulling multiple rows from the database and I need to the variable to be[code]while($row4 = mysql_fetch_array($sql4)) { $qty4 = $row4['qty']; } print $value2a.' - '.$value2b.' <> '; }[/code]Otherwise, if I use your example, it simply just gets the first row of the above and uses that.Does that make sense?ThanksEd Link to comment https://forums.phpfreaks.com/topic/35697-query-question/#findComment-169581 Share on other sites More sharing options...
CanMan2004 Posted January 26, 2007 Author Share Posted January 26, 2007 Gotcha, I misunderstood what you said.Cant thank you enough.CheersEd Link to comment https://forums.phpfreaks.com/topic/35697-query-question/#findComment-169588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.