Jump to content

Getting specific values from table with PHP


melefire

Recommended Posts

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

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/

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.