MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 29th, 2004, 08:30 AM
macin1818 macin1818 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 macin1818 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Need to display text from MySQL to screen using PHP

Hi

Forgive me for if this has already been posted but im new to php and mysql. I require help structuring a table suitable to store text and then use PHP to display that text to the screen. I have created a table:

CREATE TABLE maintext (text_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, text_body MEDIUMINT NOT NULL, PRIMARY KEY (text_id));

Then I insert this:

INSERT into maintext (text_id, text_body) VALUES (NULL, 'This is example text for to display to screen');

All I want to do is have several PHP files that display text that are in tables to screen for my web site. Im not even sure what PHP code is required to display the text. Thick arent I!

Any help would be gratefully received.

Thanks
Ben

Reply With Quote
  #2  
Old April 8th, 2004, 03:38 PM
athlon_man athlon_man is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 9 athlon_man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
A Simple way to do this, for the purpose of learning how it works, would be to type this:

<?php
mysql_connect("hostname","username","password");
mysql_select_db("database");

$sql="SELECT * FROM (tablename)";
$result=mysql_result($sql);
$num=mysql_numrows($result);
mysql_close()
?>

$i=0

while ($i<$num);
$field1=mysql_result($result,$i,"fieldnamegoeshere");

++$i;
}

This code will allow you to pull information from the database and into the code, but isn't going to display anything because it's not told to. To do that, you can make a simple script that looks like this:

echo $field1;

That's going to display the information that the script finds in the field that's specified by you. If you need an idea as to what's going on, you can visit www.jfcomputing.ca/buyer.php and you can see a table that displays information when you hit a search term. All of that data is pulled from a mysql database.

Good luck

Reply With Quote
  #3  
Old May 12th, 2004, 03:38 PM
vinhvu vinhvu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 5 vinhvu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
PHP HELP: what if I don't know the name of the column?

What if I don't know the name of the column? How can I print them all out without knowing any of the column field names?? Thanks!

Vinh Vu

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Need to display text from MySQL to screen using PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway