3dhomejoe Posted June 22, 2011 Share Posted June 22, 2011 Hello, Im trying to select a row in my database that has no value for a column and then the script generates a sha256 hash for it and updates that row. Sounds easy, something I would rather do by hand but with 200k+ rows its not worth my time. I have tried different things eg. put null in for (WHERE SHA256 ='') but that did not do anything, $num_rows just returns 0 all the time. I included a screenshot of my database so you an see whats going on. Thanks Joe <?php //die("This script does not work right now."); include ('db.php'); $con = mysql_connect($host,$username,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); $result = mysql_query("SELECT * FROM Main WHERE SHA256 = ''"); if(!$result) { $err=mysql_error(); print $err; exit(); } $num_rows = mysql_num_rows( $result ) ; if($num_rows ==0){ print "Nothing to do."; } else { echo "About to process $num_rows rows <br />\n" ; while($row = mysql_fetch_array($result)) { $id = $row['SHA256']; // echo "Deleting encid: $id <br />\n"; echo ("Updating $id"); $sha256 = hash('SHA256', $id); mysql_query("UPDATE Main SET SHA256 = '$sha256' WHERE Text = '$id' "); } } mysql_close($con); ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/240066-php-mysql-selecting-rows-where-column-is-blank/ Share on other sites More sharing options...
kenrbnsn Posted June 22, 2011 Share Posted June 22, 2011 Try this instead: <?php $result = mysql_query("SELECT * FROM Main WHERE SHA256 is NULL"); ?> Ken Link to comment https://forums.phpfreaks.com/topic/240066-php-mysql-selecting-rows-where-column-is-blank/#findComment-1233136 Share on other sites More sharing options...
3dhomejoe Posted June 22, 2011 Author Share Posted June 22, 2011 Awesome, thanks that worked out Thanks Joe Link to comment https://forums.phpfreaks.com/topic/240066-php-mysql-selecting-rows-where-column-is-blank/#findComment-1233159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.