ow-design Posted October 15, 2008 Share Posted October 15, 2008 Hi, Okay i am struggling with this one as a PHP newby, I can get information from a database using id?=(numeric figure) but how do i call from a database using a title. I have for example a table with the following columns, title, Content, Added how can i get information from a row with an address such as. www.site.com?page=Home Thank You, Ollie Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 As you normally would do. The extreme basics would be $title = $_GET['page']; $sql = "SELECT * FROM your_table WHERE title='$page'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo '<pre>'.print_r($row, true).'</pre>'; Quote Link to comment Share on other sites More sharing options...
Maq Posted October 15, 2008 Share Posted October 15, 2008 You mean? $title = $_GET['page']; $sql = "SELECT * FROM your_table WHERE title='$title'"; Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 You mean? <?php $title = $_GET['page']; $sql = "SELECT * FROM your_table WHERE title='$title'"; Woops, My bad Quote Link to comment Share on other sites More sharing options...
ow-design Posted October 15, 2008 Author Share Posted October 15, 2008 Right so that is displaying the entire row, So what is i just want to display information in diffent places of the webpage? If i do a php echo that is not working??? Quote Link to comment Share on other sites More sharing options...
sam06 Posted October 15, 2008 Share Posted October 15, 2008 You have to select each part, like this: $result = mysql_query("SELECT item FROM table WHERE title='$title'") or die(mysql_error()); $item = mysql_result ($result, 0, 'item'); Let item be whatever value you need. Then echo $item Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 You have to select each part, like this: $result = mysql_query("SELECT item FROM table WHERE title='$title'") or die(mysql_error()); $item = mysql_result ($result, 0, 'item'); Let item be whatever value you need. Then echo $item You don't need to do that. mysql_fetch_assoc returns an associative array of columns. Just save each item of the array to a variable. Then do what ever you want with the variables. $row = mysql_fetch_assoc($result); $title = $row['title']; $content = $row ['content']; echo ' <h1>'.$title.'</h1> <p>'. $content . '</p> '; Quote Link to comment Share on other sites More sharing options...
ow-design Posted October 15, 2008 Author Share Posted October 15, 2008 okay i dont know what i am doing wrong but this is not working... Would you be able to give me a complete code... To connect to a database to select from a table called pages and looking for the ?page= and the code i need to pick the title, content and author from the table row and display them individually.?? Really appreciate any help. Thank You Quote Link to comment Share on other sites More sharing options...
revraz Posted October 15, 2008 Share Posted October 15, 2008 No, but you can paste your code and we can try to tell you what you are doing wrong. Quote Link to comment Share on other sites More sharing options...
Maq Posted October 15, 2008 Share Posted October 15, 2008 Would you be able to give me a complete code... Have you even attempted to do anything? There's millions of tutorials on how to connect to a DB. Once you do that it's easy. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 15, 2008 Share Posted October 15, 2008 okay i dont know what i am doing wrong but this is not working... Would you be able to give me a complete code... To connect to a database to select from a table called pages and looking for the ?page= and the code i need to pick the title, content and author from the table row and display them individually.?? Really appreciate any help. Thank You I'm not here write scripts for you. I'm here to help/guide you. You said earlier I can get information from a database using id?=(numeric figure) With that being said, you should know how to pull data from a databased on any type of column. Quote Link to comment Share on other sites More sharing options...
ow-design Posted October 15, 2008 Author Share Posted October 15, 2008 Its okay i have orked this out now, thankyou for all your help Quote Link to comment Share on other sites More sharing options...
Maq Posted October 15, 2008 Share Posted October 15, 2008 Your welcome... topic solved then? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.