vampke Posted March 12, 2007 Share Posted March 12, 2007 Hi, Sorry to trouble you guys again with my ignorance I'm having problems with this script I'm working on. I have a MySQL database with articles in it. I want to be able to input the id-number of an article and then return the whole article. What's wrong with the following script? This is called when I hit the post button on a previous page. On the page I have an inputbox called <artnr> <?php $get_article = "SELECT id, date, comment, title FROM article WHERE id = $_POST[artnr]"; $get_article_res = mysql_query($get_article) or die(mysql_error()); $id = mysql_result($get_article_res, 'id'); $date = mysql_result($get_article_res, 'date'); $comment = mysql_result($get_article_res, 'comment'); $title = mysql_result($get_article_res, 'title'); $display_block .= " <p>$id</p> <p>$date</p> <p>$comment</p> <p>$title</p> "; ?> returning the display block gives 4 times the $id value. If I leave the $id out of the select query, it returns the date 3 time (always the first instance in the query). Why does this happen? Link to comment https://forums.phpfreaks.com/topic/42409-need-help-with-mysql-select-query/ Share on other sites More sharing options...
papaface Posted March 12, 2007 Share Posted March 12, 2007 It would probably be easier to do this: <?php $get_article = mysql_query("SELECT id, date, comment, title FROM article WHERE id = '{$_POST[artnr]}'"); list($id,$date,$comment,$title) = mysql_fetch_array($get_article); $display_block .= " <p>$id</p> <p>$date</p> <p>$comment</p> <p>$title</p> "; ?> ^^ Thats what I {would} do. Link to comment https://forums.phpfreaks.com/topic/42409-need-help-with-mysql-select-query/#findComment-205718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.