Tyler Tyler - 4 months ago 19
MySQL Question

How do I update the value of a field in a row I just selected?

I used a

to select rows from my DB that contain part of a string and this works correctly as I am getting the correct rows echoed. I now want to take those rows where the
sku LIKE '%$string%'
and input the value
into a different column in that row called
. I have tried using insert and update and I just don't seem to be getting any results in the database. Here is how I am selecting the rows, which once again is working:

$string = 'BB-BB-2017-MAR';
$result = mysql_query("SELECT * FROM cruncher.sku WHERE sku LIKE '%$string%'");
if($result === FALSE) {
while($row = mysql_fetch_array($result))
echo $row['sku'] . "</br>";

Answer Source

if you want to update value in another column, then you need to execute:

update cruncher.sku
set skugroup = sku
WHERE sku LIKE '%$string%'

if you want to create alias, then you need something like:

SELECT *, sku as skugroup FROM cruncher.sku WHERE sku LIKE '%$string%'