Jump to content

re selecting text from database where primary id =1


blui

Recommended Posts

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; ?>" />

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 = '';
?>

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.