melefire Posted November 11, 2008 Share Posted November 11, 2008 So, in my latest project I have decided to save all of the visible text a "strings" in a table in my database. The database structure is as follows: +----+------+-----------------------------+------------+ | id | name | default_value | cust_value | +----+------+-----------------------------+------------+ | 1 | str1 | This is a demo string | | | 2 | str2 | This is another demo string | | +----+------+-----------------------------+------------+ So I got the contents of the table called 'strings' like this: $strings = mysql_query("SELECT * FROM `strings`;"); I know this selects the whole table with all the data. Then I make an array out of it: $rawData = mysql_fetch_array($strings); From there I need to be able to pull out individual strings... how would i go about doing this Can anyone help? thanks Quote Link to comment https://forums.phpfreaks.com/topic/132336-getting-specific-values-from-table-with-php/ Share on other sites More sharing options...
harkly Posted November 11, 2008 Share Posted November 11, 2008 You can try this just use your info $result = mysql_query("SELECT * FROM yourtablename"); //you can use somthing like this to grab all the content while ($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns and add more if needed $id=$r["id"]; $name=$r["name"]; //display the row echo "".$id.", ".$name."<<br />"; } also here is a good site for getting the basics http://www.tizag.com/phpT/ Quote Link to comment https://forums.phpfreaks.com/topic/132336-getting-specific-values-from-table-with-php/#findComment-688011 Share on other sites More sharing options...
melefire Posted November 11, 2008 Author Share Posted November 11, 2008 that is all good, but that script prints all of the "id" values and all of the "name" values, and i just need to print one specific one, like the "default_value" for the column with the name of "str2" Quote Link to comment https://forums.phpfreaks.com/topic/132336-getting-specific-values-from-table-with-php/#findComment-688016 Share on other sites More sharing options...
corbin Posted November 11, 2008 Share Posted November 11, 2008 SELECT default_value FROM table WHERE name = 'str2'; Read http://php.net/mysql_query http://php.net/mysql_num_rows http://php.net/mysql_fetch_assoc If you don't have any idea what's going on with MySQL (SQL syntax to be specific), consider reading a MySQL tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/132336-getting-specific-values-from-table-with-php/#findComment-688042 Share on other sites More sharing options...
melefire Posted November 11, 2008 Author Share Posted November 11, 2008 that is my current setup, however when i am pulling hundreds of strings per page it gets very slow, so my idea was to pull all the strings and have PHP soft them out Quote Link to comment https://forums.phpfreaks.com/topic/132336-getting-specific-values-from-table-with-php/#findComment-688052 Share on other sites More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 Just pull what you need from the table with a WHERE clause. Quote Link to comment https://forums.phpfreaks.com/topic/132336-getting-specific-values-from-table-with-php/#findComment-688210 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.