Bman900 Posted May 1, 2009 Share Posted May 1, 2009 I have a real simple thing here. In my database I have a table called site_title with a column called title I inserted "Something here" when I ran the create table script so I can have sort of a default value there. Now I have a variable called $site_title that I want to fill with the entry that I just entered. The code I used so far is: <?php mysql_connect("changed", "changed", "changed") or die(mysql_error()); mysql_select_db("db283875085") or die(mysql_error()); $title = mysql_query("SELECT title FROM site_title"); echo "$title"; ?> I get a result of Resource id #2 How would I get to display the "Something here" that I instered into my database? Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/ Share on other sites More sharing options...
premiso Posted May 1, 2009 Share Posted May 1, 2009 <?php mysql_connect("changed", "changed", "changed") or die(mysql_error()); mysql_select_db("db283875085") or die(mysql_error()); $titleRes = mysql_query("SELECT title FROM site_title"); $title = mysql_result($titleRes, 0, 0); echo "$title"; ?> For a one column pull mysql_result works. For multiple rows/columns mysql_fetch_assoc would be the way to go. Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/#findComment-823711 Share on other sites More sharing options...
Bman900 Posted May 1, 2009 Author Share Posted May 1, 2009 That did not return anything. Am I suppose to modify something? Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/#findComment-823715 Share on other sites More sharing options...
Bman900 Posted May 1, 2009 Author Share Posted May 1, 2009 Never mind it worked. Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/#findComment-823718 Share on other sites More sharing options...
Bman900 Posted May 1, 2009 Author Share Posted May 1, 2009 <?php mysql_connect("changed", "changed", "changed") or die(mysql_error()); mysql_select_db("db283875085") or die(mysql_error()); $titleRes = mysql_query("SELECT title FROM site_title"); $title = mysql_result($titleRes, 0, 0); echo "$title"; ?> For a one column pull mysql_result works. For multiple rows/columns mysql_fetch_assoc would be the way to go. I just want to understand something. In this line: $title = mysql_result($titleRes, 0, 0); Now the first 0 is the row id right? What is the second 0 for? Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/#findComment-823857 Share on other sites More sharing options...
the182guy Posted May 1, 2009 Share Posted May 1, 2009 The third argument is optional and is used to specify the field. Only needed if you select multiple fields in your query, which in your example you don't, you only select one field. Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/#findComment-823858 Share on other sites More sharing options...
Bman900 Posted May 1, 2009 Author Share Posted May 1, 2009 Alright that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/156439-solved-adding-value-to-variable-from-databse-content/#findComment-823865 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.