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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/ 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666341 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666344 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666348 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666361 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666367 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666375 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666381 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666384 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666386 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666387 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666400 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 https://forums.phpfreaks.com/topic/128579-solved-a-little-help-indexphppagehome/#findComment-666402 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.