blui Posted March 25, 2007 Share Posted March 25, 2007 Hi I need to have the default / initial value of my form select the information already stored in the database field where the primaryid = 1 I have managed to create a recordset which collects all the data from the database as well as a echo script that prints the value out both of these are below (however I have not been able to figure out what i put in the code so that only a specific result is returned where the primaryid = 1 Any help would be greatly appreciated. recordset:- <?php mysql_select_db($database_localconnection, $localconnection); $query_Recordset1 = "SELECT * FROM cmscontent WHERE cmscontent.PRIMARYID"; $Recordset1 = mysql_query($query_Recordset1, $localconnection) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> ------------------------------------------- code that returns value:- <input name="title1" type="text" value="<?php echo $row_Recordset1['title']; ?>" /> I am assuming that the code needs to along the lines of:- <input name="title1" type="text" value="<?php echo $row_Recordset1['title'] WHERE PRIMARYID=1; ?>" /> Link to comment https://forums.phpfreaks.com/topic/44233-re-selecting-text-from-database-where-primary-id-1/ Share on other sites More sharing options...
Barand Posted March 25, 2007 Share Posted March 25, 2007 try <?php $sql = "SELECT title FROM cmscontent WHERE primaryid = '1' "; $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); if (mysql_num_rows($res) > 0) $title1 = mysql_result($res,0); else $title1 = ''; ?> Link to comment https://forums.phpfreaks.com/topic/44233-re-selecting-text-from-database-where-primary-id-1/#findComment-214829 Share on other sites More sharing options...
blui Posted March 25, 2007 Author Share Posted March 25, 2007 I tried the code you entered but it produced no results - I have tried the following code, but it keeps returning a S as a result - it should be returning Special Offers <input name="title1" type="text" value=" <?php $sql = "SELECT title FROM cmscontent WHERE PRIMARYID='1'"; mysql_query($sql) || die("An error has happened: " . mysql_error()); echo $sql['title']; ?> " /> Any thoughts anyone? Link to comment https://forums.phpfreaks.com/topic/44233-re-selecting-text-from-database-where-primary-id-1/#findComment-214943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.