Re: extracting id from db from a form field

From: Date: Fri, 27 May 2011 21:13:11 +0000
Subject: Re: extracting id from db from a form field
References: 1 2 3 4  Groups: php.db 
Request: Send a blank email to php-db+get-47815@lists.php.net to get a copy of this message
To get row 0 make the for loop change to for($i=-1; Best, Karl On May 27, 2011, at 4:08 PM, Karl DeSaulniers wrote:
Hi David, Yeah sorry, that was all of the top of the head, so I apologize if anything was incorrect. I am glad you got it working though.. Best, Karl On May 27, 2011, at 3:50 PM, David McGlone wrote:
On Fri, 2011-05-27 at 14:48 -0500, Karl DeSaulniers wrote:
Hi David, Try this.. if(!isset($_POST['ErrorCode'])) { die('You did not enter an error code!'); } else { $errorcode = $_POST['ErrorCode']; $sql = mysql_query("SELECT * FROM Sheet1 WHERE errorcode='". $errorcode."' "); if($sql && mysql_numrows($sql) > 0) { $row = mysql_fetch_array($sql); for($i=0; $i<mysql_numrows($sql); $i++) { echo ("Error Code: ".$row[$i]['errorcode']."<br />"); echo ("Error Definition: ".$row[$i]['definition']."<br />"); echo ("<br />"); } } else { die('No Error Code found in database'); } } Have not tested this, and there may be a better "short-hand" way of writing this, but hope it gets you on your way...
Thank you Karl, after a minute or two, or three ;-) I had it working, but I had to change in the first line !isset to empty. For some reason it wasn't working with !isset. and I had to change: .$row[$i]['errorcode']. to .$row['errorcode']. because it wasn't allowing for more than 1 digit in the error code number, but it was displaying the correct error definition and .$row[$i]['definition']. to .$row['definition']. had to be changed because it was displaying the error code and not the definition. Now the only problem I've got to figure out is altering it so it doesn't exclude row[0]. Blessings, David M. --PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Karl DeSaulniers Design Drumm http://designdrumm.com --PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Karl DeSaulniers Design Drumm http://designdrumm.com

« previous php.db (#47815) next »