|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 ![]() |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Need to display text from MySQL to screen using PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|