Conditional echo on update field?

OK. I have an Ajax getproduct() function that calls getproduct.php page with the id of li tag elements from multiple uls in #sidebar div. The id of each li tag references a table in the database as ‘$q=$_GET[“q”]’. All the rows in the tables called are the same and each contains a field called ‘sold’ which is empty. When The client purchases an item from a category / ul tag that only has one original item the database field for that item/sold has to be updated so that that item and row is echoed as sold!. The idea being that the item/row will not be removed from the database until confirmation or receipt of the item by the client. Other clients will be able to view the item sold but won’t be able to purchase it for some time untill the purchaser receives the item.

I’m guessing I’ll have to add a new Ajax updateproduct() function that calls updateproduct.php. I’ve added ‘Sold!’ to the ‘sold’ field and can see the result echoed and have bookmarked the sql as ‘updatesold’ and can create the updateproduct.php query. The problem is that the echoed row of the sold item contains select quantity tag with options length 1 that still shows up as 1 when another client downloads the page as well as the button still having innerHTML of ‘Buy Now!’. The purchasers select quantity options[0] is converted to ‘Sold!’ and that buttons innerHTML shows up as ‘Sold!’ but the next client won’t because only the sold field is updated. I need to know if it is better to update the whole row in phpmyadmin and copy the new query to echo the complete update or try to catch the ‘sold’ innerText’ clientside and alter the button and select quantity options from there? Any advice greatly appreciated.:confused: I might be wrong about needing a separatee updateproduct() function and updateproduct.php page and the conditions can be added to the original getproduct() function and getproduct.php? That would be a lot easier!::x

I use this technique on some sites.

You let a customer put the item in the basket, but when there is only one left pop up a message that the item stock will need to be verified before confirming its availability. Now 2,6,10,1000 people can put the last item in their basket, the first to the checkout gets the item, the others are told on checkout that the item is no longer available and new stock will be in soon.

Mandes Sorry, that won’t work for me. I’m close to what I want with manipulation of the tables in phpmyadmin basicaly using the value of the sold field in the echoed results which would mean using an updateproduct function and an updateproduct.php. I’m trying to add a conditional if else after while rows fetch array?

OK, but since your first post made very little sense to me I thought Id throw you another option.

After reading again, Im still not sure I understand fully what your trying to do.

Perhaps if you show us your Database schema it will be clearer. Sorry I cant be more help at this time with the info supplied.

Yeah Mandes, this is way to convaluted. Can you demonstrate a conditional if else after a while fetch array in php, something like this

getproduct.php


while($row = mysql_fetch_array($result))
{
if($row.['sold']!==' ')//ie. updated field value = 'Sold!'
{
echo "Sold";//should echo both types a lot more stuff, fieldset etc. HTML

}
if($row.['sold']==' ')//ie. original field value is empty
{
echo "Buy Now!" //should echo both types
}
}

Let me know if PHP will allow the conditions in the while loop for sure, so I’m not barking up the wrong tree. Thanks in advance.

yes you can put anything inside a while loop


......

while($row=mysql_fetch_array($results)){

 if ($row['field1'] == 'yes'){
  echo 'yes';
 }else{
  echo 'no';
 }
}  


Right on Mandes will be trying this and might have to alter the js script as well as CSS but I should get what I’m looking for. I searched ‘php if in while loop’ and got this which demonstrates what you said
http://php.about.com/od/learnphp/ss/php_loops.htm without the correct

$row['field']

syntax witch I thank you for. I’m wondering if I can echo both ifs and I’m probably over paranoid as it should do both.

getproduct.php
long but applicable


<?php

header('Cache-Control: no-cache');

$q=$_GET["q"];

$link=mysql_connect("localhost","root","root")or die(mysql_error( ));

mysql_select_db("bwi",$link) or die(mysql_error( ));

$sql="SELECT SQL_CALC_FOUND_ROWS * FROM ".$q." LIMIT 0, 20";

$result=mysql_query($sql);

$sql="SELECT FOUND_ROWS() AS 'found_rows';";

$rows=mysql_query($sql);

$rows=mysql_fetch_assoc($rows);

$rowsfound=$rows["found_rows"];

while($row = mysql_fetch_array($result))
{

if($row['sold']==' ')
{

/*start rowcontainer div*/

echo "<div id='rowcontainer" . $row['id'] . "' class='rowcontainer' title='Scroll to See more'>";

/*start rowcell div*/

echo "<div id='rowcell" . $row['id'] . "' class='rowcell'>";

echo "<input type='hidden' id='itemid" . $row['id'] . "' value='row" . $row['id'] . "'/>";

/*start imagecell div*/

echo "<div id='imagecell" . $row['id'] . "' class='imagecell' align='center'>";

echo "<input type='hidden' name='imgref" . $row['id'] . "' id='imgref" . $row['id'] . "' class='imgref' value='" . $row['href'] . "'/>";

echo "<img src='" . $row['src'] . "' class='image' onclick='pictureclick()' title='Click to get a better look'/>";

echo "</div>";

/*end imagecell div*/

/*start descriptioncell div*/

echo "<div id='descriptioncell" . $row['id'] . "' class='descriptioncell'>";

echo "<h1>" . $row['item'] . "</h1>";

echo "<p id='itemdescription" . $row['id'] . "' class='itemdescription'>";

echo $row['description'] ."</br>" . $row['sold'] . $row['list'] . "</p>";

echo "</div>";

/*end descriptioncell div*/

/*start ordercell div*/

echo "<div id='ordercell" . $row['id'] . "' class='ordercell'>";

echo "<fieldset id='addtoinvoice" . $row['id'] . "' class='addtoinvoice'><br/>";

echo "<input type='hidden' name='code" . $row['id'] . "' id='code" . $row['id'] . "' class='code' value='" . $row['code'] . "'/>";

echo "<input type='hidden' name='item" . $row['id'] . "' id='item" . $row['id'] . "' class=item' value='" . $row['item'] . "'/>";

echo "<label for='color'>Color:</label>";

echo $row['color'] . "<br/><br/>";

echo "<label for='size'>Size:</label>";

echo $row['size'] . "<br/>";

echo "<input type='hidden' name='price" . $row['id'] . "' id='price" . $row['id'] . "' class='price' value='" . $row['price'] . "'/><br/>";

echo "<label for='quantity'>Quantity:</label>";

echo $row['quantity'] . "<br/><br/>";

echo "<input type='hidden' name='vendor" . $row['id'] . "' id='vendor" . $row['id'] . "' value='" . $row['vendor'] . "'/>";

echo "<input type='hidden' name='ref" . $row['id'] . "' id='ref" . $row['id'] . "' value='" . $row['href'] . "'/>";

echo "<p class='backforward'>";

echo "<span class='row' >".$row['id']."</span>";

echo "&nbsp;";

echo "of";

echo "&nbsp;";

echo "<span class='rowsfound' >".$rowsfound."&nbsp;items</span>";

echo "</p>";

echo "<p class='bought'></p>";

/*start buttoncontainer div*/

echo "<div id='buttoncontainer" . $row['id'] . "' class='buttoncontainer'>";

echo "<span id='value" . $row['id'] . "' class='value'>" . $row['price'] . "</span>";

echo "<button name='buynow" . $row['id'] . "' id='buynow" . $row['id'] . "' class='button' onclick='addtoinvoice()' type='button' title='Buy Now!'/>Buy Now!</button>";
//change 'Buy Now!'  and may be class='button' to change onclick??
echo "</div>";

/*end buttoncontainer div*/

echo "</fieldset>";

echo "</div>";

/*end ordercell div*/

echo "</div>";

/*end rowcell div*/

echo "</div>";

/*end rowcontainer div*/


}

if($row['sold']==' ')
{

/*start rowcontainer div*/

echo "<div id='rowcontainer" . $row['id'] . "' class='rowcontainer' title='Scroll to See more'>";

/*start rowcell div*/

echo "<div id='rowcell" . $row['id'] . "' class='rowcell'>";

echo "<input type='hidden' id='itemid" . $row['id'] . "' value='row" . $row['id'] . "'/>";

/*start imagecell div*/

echo "<div id='imagecell" . $row['id'] . "' class='imagecell' align='center'>";

echo "<input type='hidden' name='imgref" . $row['id'] . "' id='imgref" . $row['id'] . "' class='imgref' value='" . $row['href'] . "'/>";

echo "<img src='" . $row['src'] . "' class='image' onclick='pictureclick()' title='Click to get a better look'/>";

echo "</div>";

/*end imagecell div*/

/*start descriptioncell div*/

echo "<div id='descriptioncell" . $row['id'] . "' class='descriptioncell'>";

echo "<h1>" . $row['item'] . "</h1>";

echo "<p id='itemdescription" . $row['id'] . "' class='itemdescription'>";

echo $row['description'] ."</br>" . $row['sold'] . $row['list'] . "</p>";

echo "</div>";

/*end descriptioncell div*/

/*start ordercell div*/

echo "<div id='ordercell" . $row['id'] . "' class='ordercell'>";

echo "<fieldset id='addtoinvoice" . $row['id'] . "' class='addtoinvoice'><br/>";

echo "<input type='hidden' name='code" . $row['id'] . "' id='code" . $row['id'] . "' class='code' value='" . $row['code'] . "'/>";

echo "<input type='hidden' name='item" . $row['id'] . "' id='item" . $row['id'] . "' class=item' value='" . $row['item'] . "'/>";

echo "<label for='color'>Color:</label>";

echo $row['color'] . "<br/><br/>";

echo "<label for='size'>Size:</label>";

echo $row['size'] . "<br/>";

echo "<input type='hidden' name='price" . $row['id'] . "' id='price" . $row['id'] . "' class='price' value='" . $row['price'] . "'/><br/>";

echo "<label for='quantity'>Quantity:</label>";

echo $row['quantity'] . "<br/><br/>";

echo "<input type='hidden' name='vendor" . $row['id'] . "' id='vendor" . $row['id'] . "' value='" . $row['vendor'] . "'/>";

echo "<input type='hidden' name='ref" . $row['id'] . "' id='ref" . $row['id'] . "' value='" . $row['href'] . "'/>";

echo "<p class='backforward'>";

echo "<span class='row' >".$row['id']."</span>";

echo "&nbsp;";

echo "of";

echo "&nbsp;";

echo "<span class='rowsfound' >".$rowsfound."&nbsp;items</span>";

echo "</p>";

echo "<p class='bought'></p>";

/*start buttoncontainer div*/

echo "<div id='buttoncontainer" . $row['id'] . "' class='buttoncontainer'>";

echo "<span id='value" . $row['id'] . "' class='value'>" . $row['price'] . "</span>";

echo "<button name='buynow" . $row['id'] . "' id='buynow" . $row['id'] . "' class='button' onclick='addtoinvoice()' type='button' title='Buy Now!'/>" . $row['sold'] ."</button>";
//change
echo "</div>";

/*end buttoncontainer div*/

echo "</fieldset>";

echo "</div>";

/*end ordercell div*/

echo "</div>";

/*end rowcell div*/

echo "</div>";

/*end rowcontainer div*/


}

echo "<link id='dognuts' rel='stylesheet' type='text/css' href='styles/product.css'/>";

mysql_close($link);
?>
 

Please let me know if any syntax is wrong. I’m going nuts trying to decide how I’m going to handle the change of onclick but it may as well be done server side.:nono:

ok the script above threw this error


Parse error: syntax error, unexpected $end in D:\\use_ide_1\\UniServer\\www\\getproduct.php on line 252

probably syntax error. will have to check it out latter!

OK please, before you go any further, please spend a few hours learning how to format your code, the code you posted will be totally unreadable by you just months after youve finished the project.

Unless you are going to be referencing the html objects later, there is no need to give them a unique ID and NAME, that will cut down a lot on the coding you have currently.

HTML can be written outside the <?php ?> tags to avoid constant use of echo statements.

Honestly those few hours now learning to make your code more easily readable will save countless hours thoughout the rest of your career.

Unexpected $end is covered in the Common PHP Problems thread.

Mandes & StarLion, thanks for the tips. I’ll be able to express my requests better as soon as I get more comfortable with PHP.

HTML can be written outside the <?php ?> tags to avoid constant use of echo statements.

Could you show me an example of this using the getproduct.php format or

$q=$_GET["q"];

I’ve seen it before but never used it.

http://www.webdeveloper.com/forum/showthread.php?t=102731

no need to reinvent the wheel, especially on Friday afternoon.

OK. Guys, I didn’t close the second if bracket. The error reported line pointed to an echo div end just before the one closing bracket I had on the last if. When I added the second bracket everything worked fine. I’d still like to know how to avoid the repetitive echo statements by placing HTML after ?> any direction greatly appreciated. Also, I use the more modern method of writing ‘scripts’ which helps us dyslexics overcome the closing bracket problem, ie.


while($row=mysql_fetch_array($results)){

 if ($row['field1'] == 'yes'){
  echo 'yes';
 }else{
  echo 'no';
 }
}

//I would write

while($row=mysql_fetch_array($results))
{
if ($row['field1'] == 'yes')
{
echo 'yes';
}
else// My case, another if
{
echo 'no';
}
}

Some how I can see the opening and closing better that way:x
Also, I’m questioning the addition of ‘ids’ and class Names as well, since most of the JS/CLIENT SIDE is node oriented and get elements by id isn’t really used much. Any suggestions about that would certainly be appreciated too!

you had

echo "<p class='backforward'>"; 

echo "<span class='row' >".$row['id']."</span>"; 

echo "&nbsp;"; 

echo "of"; 

echo "&nbsp;"; 

echo "<span class='rowsfound' >".$rowsfound."&nbsp;items</span>"; 

echo "</p>"; 


outside php tags becomes


<?php
...more phpscript here
?>
<p class='backforward'> 
 <span class='row' ><?php echo $row['id']; ?></span>
 &nbsp;of&nbsp
 <span class='rowsfound'><?php echo $rowsfound; ?>&nbsp;items</span> 
</p>

Mandes, thanks for that, I just saw that on other site though I don’t see how it simplifies matters yet. The other thing I finally noticed was that only one of the ifs seems to be echoing correctly? abbreviated—


while($row = mysql_fetch_array($result))
{
if($row['sold']==' ')
{
echo "<button name='buynow" . $row['id'] . "' id='buynow" . $row['id'] . "' class='button' onclick='addtoinvoice()' type='button' title='Buy Now!'/>Buy Now!</button>";
//Buy Now! doesn't show up as button innerText??
}
if($row['sold']!==' ')
{
echo "<button name='buynow" . $row['id'] . "' id='buynow" . $row['id'] . "' class='button' onclick='addtoinvoice()' type='button' title='Sold!'/>" . $row['sold'] . "</button>";
//Sold! does show up as button innerText??
}
}

Yeah I only saw the HTML output I was looking for? The other buttons show up as lines/CSS Borders only? The title shows up though with mouseover?
Actually, the title shows up as ‘Sold!’ on all buttons?

Mandes, It turns out I do need the

$row['id']

echoed as I have JS that is writen like so

document.getElementById('rowcontainer0').scrollIntoView(true);

This Keeps throwing JS error: getElementById is null? I May be missing something in the while loop as only parts of the CSS is functioning right?

Updated getproduct.php


<?php

header('Cache-Control: no-cache');

$q=$_GET["q"];

$link=mysql_connect("localhost","root","root")or die(mysql_error( ));

mysql_select_db("bwi",$link) or die(mysql_error( ));

$sql="SELECT SQL_CALC_FOUND_ROWS * FROM ".$q." LIMIT 0, 20";

$result=mysql_query($sql);

$sql="SELECT FOUND_ROWS() AS 'found_rows';";

$rows=mysql_query($sql);

$rows=mysql_fetch_assoc($rows);

$rowsfound=$rows["found_rows"];

$buy=' ';

while($row = mysql_fetch_array($result))
{

echo $rows;
//not sure this is right?

}

mysql_close($link);
?>

<div id="rowcontainer<?php echo $row['id']; ?>" class="rowcontainer" title="Scroll to See more">
//I'm sure echo $row['id'];  is not right as it throws the error!?
<div id="rowcell<?php echo $row['id']; ?>" class="rowcell">

<input type="hidden" id="itemid<?php echo $row['id']; ?>" value="row<?php echo $row['id']; ?>"/>
//not sure the value of a tag can be echoed this way either?
<div id="imagecell<?php echo $row['id']; ?>" class="imagecell" align="center">

<input type="hidden" name="imgref<?php echo $row['id']; ?> id="imgref"<?php echo $row['id']; ?>" class="imgref" value="<?php echo $row['href']; ?>"/>

<img src="<?php echo $row['src']; ?>" class="image" onclick="pictureclick()" title="Click to get a better look"/>

</div>

<div id='descriptioncell<?php echo $row['id']; ?>" class="descriptioncell">

<h1><?php echo $row['item']; ?></h1>

<p id="itemdescription<?php echo $row['id']; ?>" class="itemdescription">

<?php echo $row['description']; ?></br><?php echo $row['sold']; ?><?php echo $row['list']; ?></p>

</div>

<div id="ordercell<?php echo $row['id']; ?>" class="ordercell">

<fieldset id="addtoinvoice<?php echo $row['id']; ?>" class="addtoinvoice"><br/>

<input type="hidden" name="code<?php echo $row['id']; ?>" id="code<?php echo $row['id']; ?>" class="code" value="<?php echo $row['code']; ?>"/>

<input type="hidden" name="item<?php echo $row['id']; ?>" id="item<?php echo $row['id']; ?>" class="item" value="<?php echo $row['item']; ?>"/>

<label for='color'>Color:</label>

<?php echo $row['color']; ?><br/><br/>

<label for='size'>Size:</label>

<?php echo $row['size']; ?><br/>

<input type="hidden" name="price<?php echo $row['id']; ?>" id="price<?php echo $row['id']; ?>" class="price" value="<?php echo $row['price']; ?>"/>

<br/>

<label for="quantity">Quantity:</label>

<?php echo $row['quantity']; ?><br/><br/>

<input type="hidden" name="vendor<?php echo $row['id']; ?>" id="vendor<?php echo $row['id']; ?>" value="<?php echo $row['vendor']; ?>"/>

<input type="hidden" name="ref<?php echo $row['id']; ?>" id="ref<?php echo $row['id']; ?>" value="<?php echo $row['href']; ?>"/>

<p class="backforward">

<span class="row"><?php echo $row['id']; ?></span>

&nbsp;of&nbsp

<span class="rowsfound"><?php echo $rowsfound; ?>&nbsp;items</span>

</p>

<p class="bought"></p>

<div id="buttoncontainer<?php echo $row['id']; ?>" class="buttoncontainer">

<span id="value<?php echo $row['id']; ?>" class="value" ><?php echo $row['price']; ?></span>

<button name="buynow<?php echo $row['id']; ?>" id="buynow<?php echo $row['id']; ?>" class="button" onclick="addtoinvoice()" type="button" title="Buy Now!"/>Buy Now!</button>

</div>

</fieldset>

</div>

</div>

</div>

<link id="dognuts" rel="stylesheet" type="text/css" href="styles/product.css"/>
//not sure CSS link is right?

Sorry if this is too long. I need help on the whole thing:nono:

Congrats, your code is looking much more better now, and easier to read :slight_smile:

But for some reason youve removed all your html and everything outside your while loop ?? Thats why nothings working, the variables $row[‘xxx’] wont return anything once outside the while loop, your javascript is returning errors because the id tag its looking for doesnt exist.

Try this


<?php 
header('Cache-Control: no-cache'); 
 $q=$_GET["q"]; 
$link=mysql_connect("localhost","root","root")or die(mysql_error( )); 
mysql_select_db("bwi",$link) or die(mysql_error( )); 
$sql="SELECT SQL_CALC_FOUND_ROWS * FROM ".$q." LIMIT 0, 20"; 
$result=mysql_query($sql); 
$sql="SELECT FOUND_ROWS() AS 'found_rows';"; 
$rows=mysql_query($sql); 
$rows=mysql_fetch_assoc($rows); 
$rowsfound=$rows["found_rows"];  
$buy=' '; 
while($row = mysql_fetch_array($result))  
{ // start while loop
?>

<div id="rowcontainer<?php echo $row['id']; ?>" class="rowcontainer" title="Scroll to See more">  
<div id="rowcell<?php echo $row['id']; ?>" class="rowcell"> 

<input type="hidden" id="itemid<?php echo $row['id']; ?>" value="row<?php echo $row['id']; ?>"/>  
<div id="imagecell<?php echo $row['id']; ?>" class="imagecell" align="center"> 

<input type="hidden" name="imgref<?php echo $row['id']; ?> id="imgref"<?php echo $row['id']; ?>" class="imgref" value="<?php echo $row['href']; ?>"/> 

<img src="<?php echo $row['src']; ?>" class="image" onclick="pictureclick()" title="Click to get a better look"/> 

</div> 
  
<div id='descriptioncell<?php echo $row['id']; ?>" class="descriptioncell"> 
 <h1><?php echo $row['item']; ?></h1> 
 <p id="itemdescription<?php echo $row['id']; ?>" class="itemdescription"> 
 <?php echo $row['description']; ?></br><?php echo $row['sold']; ?><?php echo $row['list']; ?></p> 
</div> 
  
<div id="ordercell<?php echo $row['id']; ?>" class="ordercell"> 
 <fieldset id="addtoinvoice<?php echo $row['id']; ?>" class="addtoinvoice"><br/> 

 <input type="hidden" name="code<?php echo $row['id']; ?>" id="code<?php echo $row['id']; 
 ?>" class="code" value="<?php echo $row['code']; ?>"/> 

 <input type="hidden" name="item<?php echo $row['id']; ?>" id="item<?php echo $row['id']; 
 ?>" class="item" value="<?php echo $row['item']; ?>"/> 

 <label for='color'>Color:</label> 

 <?php echo $row['color']; ?><br/><br/> 

 <label for='size'>Size:</label> 

 <?php echo $row['size']; ?><br/> 

 <input type="hidden" name="price<?php echo $row['id']; ?>" id="price<?php echo $row['id']; 
 ?>" class="price" value="<?php echo $row['price']; ?>"/> 

 <br/> 

 <label for="quantity">Quantity:</label> 

 <?php echo $row['quantity']; ?><br/><br/> 

 <input type="hidden" name="vendor<?php echo $row['id']; ?>" id="vendor<?php echo $row['id']; 
 ?>" value="<?php echo $row['vendor']; ?>"/> 

 <input type="hidden" name="ref<?php echo $row['id']; ?>" id="ref<?php echo $row['id']; ?>" value="
 <?php echo $row['href']; ?>"/> 

 <p class="backforward"> 
  <span class="row"><?php echo $row['id']; ?></span> 
  &nbsp;of&nbsp 
  <span class="rowsfound"><?php echo $rowsfound; ?>&nbsp;items</span> 
 </p> 

 <p class="bought"></p> 
  <div id="buttoncontainer<?php echo $row['id']; ?>" class="buttoncontainer"> 
  <span id="value<?php echo $row['id']; ?>" class="value" ><?php echo $row['price']; ?></span> 
  <button name="buynow<?php echo $row['id']; ?>" id="buynow<?php echo $row['id']; 
  ?>" class="button" onclick="addtoinvoice()" type="button" title="Buy Now!"/>Buy Now!</button>
 
</div> 
</fieldset> 
</div> 
</div> 
</div> 

<?php
} // end while loop
mysql_close($link); 
?>  


<link id="dognuts" rel="stylesheet" type="text/css" href="styles/product.css"/> 
//not sure CSS link is right?

Mandes, Wow swami, I figured it had to do with the while loop closure, I’ll check it out. The other thing is the CSS link, should that be outside the loop? These are basic PHP principles I know and unfortunately I’ve completely missed them in any of the online demonstrations of PHP?

while($row = mysql_fetch_array($result))
{ // start while loop
?>

Also the closing ‘?>’ after the opening while brace? Weird science.

Actually, I’m getting the same result, most of the CSS is screwed up and getElementsBy anything are totally shot in the JS?

Mandes, I realize now why the JS and CSS are screwed up. Before I was echoing the div ‘#rowcontainer’ for every div ‘#rowcell’ which added an extra element for every row found in the database, thereby screwing up any nodes referenced etc.

This means a total overhaul of the JS.

As long as this is the correct PHP construct, I’ll proceed with changes. ie. ‘The CSS link is outside of the while loop?’ and ‘The opening and closing ?> PHP tags are in the right place as you have demonstrated?’

Thanks again for you’re patience.

Mandes, everything is working fine now, including the CSS and JS, there where no problems with the node values after all!? Now I’ve changed the PHP construct to the correct methode I’m still back to the original post problem.

Conditional echo on update field?
if and else only return the first statement?

Button snipit


<button
name="buynow<?php echo $row['id'];?>"
id="buynow<?php echo $row['id'];?>"
class="button" onclick="addtoinvoice()" type="button"
title="
<?php if($row['sold']=='Sold!')
echo $row['sold'];//returns
else
echo 'Buy Now';//returns empty?
?>
"/>
<?php
if($row['sold']!==' ')
echo $row['sold'];//returns 'Sold!'
else
echo  'Buy Now';//returns empty button with no innerText???:nono:
?>
</button>