Jump to content

Query Question


CanMan2004

Recommended Posts

Hi all

I 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 like

IPODS - 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 help

Thanks

Ed
Link to comment
https://forums.phpfreaks.com/topic/35697-query-question/
Share on other sites

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

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?

Thanks

Ed
Link to comment
https://forums.phpfreaks.com/topic/35697-query-question/#findComment-169581
Share on other sites

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.