jat421 Posted December 9, 2010 Share Posted December 9, 2010 Hi, I am trying to delete a row that has be read. Below is the code. I can't figure out how to delete it after it has been printed on the screen. Any help is much appreciated. Thanks! <?php echo "Today is " . date("Y/m/d"); $server = "Computer\\test"; $options = array( "UID" => "sa", "PWD" => "root", "Database" => "SetNo" ); $conn = sqlsrv_connect($server, $options); if ($conn === false) die("<pre>".print_r(sqlsrv_errors(), true)); $result=sqlsrv_query($conn, "select * from tblCus"); [color=red]$delete=sqlsrv_query($conn, "delete from tblCus where result.row[1]");[/color] $row = sqlsrv_fetch_array($result); echo "<br />"; echo "<br />"; echo "<br />"; echo "Number:" . " " . $row[1]; echo "<br />"; sqlsrv_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/221163-delete-from-database/ Share on other sites More sharing options...
requinix Posted December 9, 2010 Share Posted December 9, 2010 1. $row only exists after $row = sqlsrv_fetch_array($result); You can't use it before that point. 2. "where result.row[1]" is not a valid condition in T-SQL. You need something like "where field = value". 3. Are you trying to display the whole table or just the first row? Quote Link to comment https://forums.phpfreaks.com/topic/221163-delete-from-database/#findComment-1145136 Share on other sites More sharing options...
jat421 Posted December 9, 2010 Author Share Posted December 9, 2010 Just trying to display the first row and once it's displayed delete the first row from the database. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221163-delete-from-database/#findComment-1145140 Share on other sites More sharing options...
jat421 Posted December 9, 2010 Author Share Posted December 9, 2010 oh yes you are right $row is after. I couldn't possible use that duhh. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221163-delete-from-database/#findComment-1145141 Share on other sites More sharing options...
jat421 Posted December 10, 2010 Author Share Posted December 10, 2010 I got it working thanks for your help! I assigned $row[1] to a variable and provided that as a sql delete paramater. Just one more question. I want only one person reading and writing to the table at one time. How can that be done? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221163-delete-from-database/#findComment-1145180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.