Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Lionsanime Directory   1,000 Directory Submissions   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 02-25-2005, 03:56 PM   #1 (permalink)
SN3
Contributing Member
 
SN3's Avatar
 
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
iTrader: 0 / 0%
Latest Blog:
None

SN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really nice
Send a message via AIM to SN3 Send a message via Yahoo to SN3
Database Question

What is the code to get the field "location" from a database and then print it out in a php file?
SN3 is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 02-25-2005, 05:41 PM   #2 (permalink)
SVB
Inactive
 
SVB's Avatar
 
Join Date: 10-13-03
Posts: 7,481
iTrader: 0 / 0%
Latest Blog:
None

SVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest orderSVB is a web professional of the highest order
Send a message via Yahoo to SVB
What do you mean field location?
"ID
Surname
Forename"
You mean like, Forename is location 3?
SVB is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-25-2005, 05:43 PM   #3 (permalink)
SN3
Contributing Member
 
SN3's Avatar
 
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
iTrader: 0 / 0%
Latest Blog:
None

SN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really nice
Send a message via AIM to SN3 Send a message via Yahoo to SN3
No, the field entitled "location" is in a database. How do I get the content in the field "location" to print out.
SN3 is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-25-2005, 06:42 PM   #4 (permalink)
Possible Terrorist
 
kwvarga's Avatar
 
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
iTrader: 0 / 0%
Latest Blog:
A+ Certification

kwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web pro
Send a message via AIM to kwvarga
Code:
<?php $link = mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $query = "SELECT location FROM table"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $location = $row[0]; echo "Location: " . $location; mysql_close($link); ?>
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
kwvarga is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2005, 08:37 AM   #5 (permalink)
v7n Mentor
 
hatchet's Avatar
 
Join Date: 10-11-03
Posts: 1,149
iTrader: 0 / 0%
Latest Blog:
None

hatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nicehatchet is just really nice
A little more efficient to do

$row = mysql_fetch_assoc($result);
echo "Location: " . $row['location'];

mysql_fetch_array pulls the indices and the names.. assoc only pulls the field names.

You should also have some error checking (this goes before mysql_fetch_assoc()
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}

and if you're expecting multiple rows of information (after the last code segment)
while ($row = mysql_fetch_assoc($result)) {
echo $row["location"];
echo '<br>';
}

and you don't have to close the connection - php will do it automatically.
hatchet is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-26-2005, 10:03 AM   #6 (permalink)
SN3
Contributing Member
 
SN3's Avatar
 
Join Date: 10-13-03
Location: Work, USA
Posts: 5,382
iTrader: 0 / 0%
Latest Blog:
None

SN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really niceSN3 is just really nice
Send a message via AIM to SN3 Send a message via Yahoo to SN3
Thanks!
SN3 is offline  
Add Post to del.icio.us
Reply With Quote
Old 02-27-2005, 09:55 AM   #7 (permalink)
Possible Terrorist
 
kwvarga's Avatar
 
Join Date: 10-13-03
Location: Tuscaloosa, AL or Atlanta
Posts: 4,904
iTrader: 0 / 0%
Latest Blog:
A+ Certification

kwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web prokwvarga is a highly respected web pro
Send a message via AIM to kwvarga
oh yeah thats right, i forgot you dont have to close it, ive been dealing with multi-mysql server scripts so i have had weird errors if i didnt close it. hmm
__________________
Kyle Varga
"m3lt/theSpear"
student, web designer/coder, future IT consultant
Experience: PHP/MySQL, Java, C++, MS-SQL
kwvarga is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with database and PHP orionjade Coding Forum 3 10-03-2007 09:47 PM
PHP Database help Please? swiftmed Web Design Lobby 5 12-13-2006 09:21 AM
Question about question marks? clipse Coding Forum 18 03-15-2006 03:21 PM
vB Skinning Question. CSS Question. JuggoPop Coding Forum 10 02-28-2006 01:44 PM
How to with Dreamweaver/database Question? Buskerdoo Coding Forum 3 05-15-2005 07:14 PM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 04:36 AM.
© Copyright 2008 V7 Inc