PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers 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 June 25th, 2002, 08:54 PM
mr_fitz mr_fitz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 13 mr_fitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
print echo specific, single cell from mysql database

Sounds simple to me, query my mysql database for the cell Robert and MOCi (which happens to equal the integer: 51)

Here is the main part of what I have tried so far:

$sql_query = "SELECT Name, MOCi FROM mydatabase WHERE 1 AND Name = Robert";

//store the queried cell in the variable
//named $result
$result = mysql_query($sql_query);

//display the queried cell

echo ($result);

This "echos" nothing but gives not errors either.

It seems that all the example code I find out there is based on arrays. This should be basic, but I am fairly new to all this.

thanks in advance for your help!

Reply With Quote
  #2  
Old June 25th, 2002, 11:21 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: print echo specific, single cell from mysql database

$result is actually a 'result set'. You must now retrieve some data from the result set..try this:

$sql_query = "SELECT Name, MOCi FROM mydatabase WHERE 1 AND Name = Robert";

//store the queried cell in the variable
//named $result
$result = mysql_query($sql_query);

//get one row of data from the result set
$row = mysql_fetch_array($result);

//display the queried cell
echo ($row['MOCi']);


Reply With Quote
  #3  
Old June 26th, 2002, 12:10 AM
mr_fitz mr_fitz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 13 mr_fitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: print echo specific, single cell from mysql database

Cheers Anonymous but...I had to resort to the following:
//this is supposed to query the database for
//the exact cell needed
$sql_query = "SELECT MOCi, Name FROM moc_db1 LIMIT 3, 1";
// "SELECT Name, MOCi FROM moc_db1 WHERE 1 AND Name = Robert"
//gives: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
___________________
NOTE1:
Using the LIMIT parameter I can, in effect specify the name, but this is awkward. For some reason the Name = Robert gives the error above

NOTE2:
SELECT can be * (all the data) since only the desired column is printed in this command:
echo ($row[MOCi]);

OUTSTANDING QUESTION:
Any idea why the mysql_query does not like me specifying Name = Robert - or something similar? (I cut and pasted the mysql code straight from phpmyadmin just be sure and, no good). It would be much cleaner to specify the cell without LIMIT.

cheers.

Reply With Quote
  #4  
Old June 26th, 2002, 01:06 AM
mr_fitz mr_fitz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 13 mr_fitz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It DOES work with Name = Robert

Isert this in any of the scripts above and they should work:

Name = 'Robert'

Since this is the default text format in a text field Name = requires ' '

all works fine now.

thanks again
anonymous

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > print echo specific, single cell from mysql database


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 2 hosted by Hostway