Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing one field to fill another field in MySQL
    primarykey
    data
    text
    <p>I am new to PHP/MySQL and am working my way through the basics.</p> <p>I have a MySQL database scwdb (that I moved from Access 2000 which my Windows 7 won't work with) with a table tblsplintersbowlinventory which has 2 fields: </p> <p>fields and data:</p> <pre><code>txtProductBowlCode data examples: OakSc07-001, MapleTi07-030, MapleTi07-034, BlackLimba07-002, AshSc07-017 txtProductPrimarySpecies data examples: Oak, Maple, Maple, BlackLimba, Ash </code></pre> <p>In other words, I want to record just the species in the txtProductPrimarySpecies field.</p> <p>I tried the following PHP script:</p> <pre><code> &lt;?php $con = mysql_connect("localhost","xxxxxxx","zzzzzzz"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("scwdb", $con); $species = 'Maple'; mysql_query("UPDATE tblsplintersbowlinventory WHERE txtProductBowlCode LIKE $species SET txtProductPrimarySpecies=$species%"); echo "done"; mysql_close($con); ?&gt; </code></pre> <p>It seems to run, does not show an error and prints "done", but when I check the database I don't see any changes.</p> <p>What am I missing?</p> <p>This db has over 600 records, and I added this new txtProductPrimarySpecies field to make my searches easier while leaving the full code which has specific info on the bowl. There are several species that I need to do this to, so I plan on using a loop to run through a list of species. </p> <h1>How would I code that loop to read a list of species?</h1> <p>OK, I found the way to make this work!</p> <pre><code> &lt;?php $con = mysql_connect("localhost","xxxxxx","zzzzzzz"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("scwdb", $con); $species = 'Maple'; $result = mysql_query("UPDATE tblsplintersbowlinventory SET txtProductPrimarySpecies = '$species' WHERE txtProductBowlCode LIKE '$species%'"); $result = mysql_query("SELECT * FROM tblsplintersbowlinventory WHERE txtProductBowlCode LIKE '$species%'"); echo "&lt;table border='1'&gt; &lt;tr&gt; &lt;th&gt;Index&lt;/th&gt; &lt;th&gt;Bowl Code&lt;/th&gt; &lt;th&gt;Species&lt;/th&gt; &lt;/tr&gt;"; while($row = mysql_fetch_array($result)) { echo "&lt;tr&gt;"; echo "&lt;td&gt;" . $row['intProductID'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['txtProductBowlCode'] . "&lt;/td&gt;"; echo "&lt;td&gt;" . $row['txtProductPrimarySpecies'] . "&lt;/td&gt;"; echo "&lt;/tr&gt;"; } echo "&lt;/table&gt;"; echo "done"; mysql_close($con); ?&gt; </code></pre> <p>This worked, and I manually changed the $species value and ran it for each of the species of wood in the database...since this was a one time shot it made more sense not to use a list and loop through it - I was bound to miss one or two species anyway.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload