Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using PHP to read strings from a MySQL db
Old 11-08-2008, 05:09 PM Using PHP to read strings from a MySQL db
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
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:
Code:
+----+------+-----------------------------+------------+
| 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:
PHP Code:
$strings mysql_query("SELECT * FROM `strings`;"); 
but after that I am unsure as to how I would go about placeing these strings in my code.

Can anyone help?
thanks

Last edited by melefire; 11-08-2008 at 05:11 PM..
melefire is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-08-2008, 05:27 PM Re: Using PHP to read strings from a MySQL db
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Read the manual section about mysql.
You will find everything that you need.
http://www.php.net/manual/en/book.mysql.php

Even on the mysql_query() documentation page, you have an example on how to perform the query and get the column values. Look at the example 2.
http://www.php.net/manual/en/function.mysql-query.php
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-08-2008, 05:37 PM Re: Using PHP to read strings from a MySQL db
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
thank you for the speedy response, however from what i read that does not fully help me. I already know how to print a whole array of all the values, but I need away to print just one on the values from whole selected dataset

thanks
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-08-2008, 08:23 PM Re: Using PHP to read strings from a MySQL db
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
well, then just print it:
PHP Code:
$sql="select * from x";
$r=mysql_query($sql);
while(
$res=mysql_fetch_array($r)){
  print 
$res['column_name'];

Might I suggest that you really read the tutorial.
Accessing 1 array value is something so basic, that you will have many more problems later on if you don't understand how functions, variables and iterations are working.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-09-2008, 06:09 AM Re: Using PHP to read strings from a MySQL db
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You should iterate though your mysql result set and create indexed array like this:
$indexed[$record->name] = $record
After that in your templates you may refer to it like this:
<?= $indexed['str1']->default_value ?>
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 11-11-2008, 03:18 PM Re: Using PHP to read strings from a MySQL db
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
thanks
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-11-2008, 03:47 PM Re: Using PHP to read strings from a MySQL db
melefire's Avatar
Experienced Talker

Posts: 46
Name: matt
Trades: 0
Quote:
Originally Posted by mtishetsky View Post
You should iterate though your mysql result set and create indexed array like this:
$indexed[$record->name] = $record
After that in your templates you may refer to it like this:
<?= $indexed['str1']->default_value ?>
I seem to still need a little help, could you please explain your code abit, i just dont understand quite how to use it.

thanks
melefire is offline
Reply With Quote
View Public Profile
 
Old 11-12-2008, 01:59 AM Re: Using PHP to read strings from a MySQL db
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
$sql="select * from x";
$r=mysql_query($sql);
while(
$res=mysql_fetch_array($r)){
  
$indexed[$res->name] = $res;
}
...
echo 
"Here is str1 value: {$indexed['str1']->default_value}"
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Using PHP to read strings from a MySQL db
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33552 seconds with 12 queries