I created a simple lame CMS but i wanted to be able select a specific record. My db looks like CMS -id -detail -area and so far I've inserted about 3 entries into CMS INSERT INTO 'CMS' ('1','blah blah', 'Create'); INSERT INTO 'CMS' ('2','blah blah', 'success'); INSERT INTO 'CMS' ('3','blah blah', 'home'); I know that's not written 100% right but I'm just giving you info to work with. Let say I have home.php, create.php, and sucess.php. I want to call row 1 (id 1) on page create.php but I specifically just want to call that one record. I did a query (SELECT detail FROM CMS where id='1'); $detail = $_POST['detail']; And then I did echo $detail later in the script to display id=1's details. I only need that one value to display and I want that specific row. I keep looking around and trying out solutions but they all call multiple $rows or values. I just need one value which is identified by id. I appreciate the help, if you can lead me in the right direction. I'm getting more into PHP now and some things aren't entirely clear to me yet. I know how to do error checking and such but yeah... Oh and register globals is off, so I can't do it the way some have suggested on other sites.
<?php $sql = "SELECT detail FROM CMS WHERE id = '1'"; //execute query.. $result = mysql_query($sql); //turn data from sql query into an array... $row = mysql_fetch_array($result); //extract specic entry from the array $row... $detail = $row['detail']; //display detail... echo $detail; ?> PHP:
While danx works, I'd do a mysql_result instead of a fetch_array. No need to get an array if your just getting one value. <?php //The query $query = "SELECT detail FROM cms WHERE id='1'"; //Execute your statement $result = mysql_query($query); //Return the detail filed $detail = mysql_result($result, 0, 0); echo $detail; ?> PHP: