|
Author |
Message |
mr_fitz
Junior WebHelper
Joined: 25 Jun 2002
Posts: 4
|
Posted:
Tue Jun 25, 2002 6:51 pm (21 years, 10 months ago) |
|
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! |
________________________________ mr_fitz |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue Jun 25, 2002 7:01 pm (21 years, 10 months ago) |
|
|
|
|
mr_fitz
Junior WebHelper
Joined: 25 Jun 2002
Posts: 4
|
Posted:
Tue Jun 25, 2002 8:12 pm (21 years, 10 months ago) |
|
Okay, but I was pretty much this far already:
I used the simpler version, in note 2 to produce:
$query = "SELECT MOCi FROM mydatabase";
$query_result_handle = mysql_query ($query) or die ('The query failed! table_name must be a valid table name that exists in the database specified in mysql_select_db');
# make sure that we recieved some data from our query
$num_of_rows = mysql_num_rows ($query_result_handle) or die ("The query: '$query' did not return any data");
print "The query: '$query' returned $num_of_rows rows of data.
";
# use mysql_fetch_row to retrieve the results
while ($row = mysql_fetch_row ($query_result_handle))
{
$robert=$row[0];
print "Value stored at the first index position is $row[0]
";
}
print "Robert is: $robert";
?>
Which produces:
MOCi™ : The query: 'SELECT MOCi FROM mydatabase' returned 14 rows of data. Value stored at the first index position is 51 Value stored at the first index
position is 99 Value stored at the first index position is 66 Value stored at the first index position is 34 Value stored at the first index position is 40 Value stored at
the first index position is 42 Value stored at the first index position is 60 Value stored at the first index position is 43 Value stored at the first index position is 84
Value stored at the first index position is 62 Value stored at the first index position is 86 Value stored at the first index position is 84 Value stored at the first index
position is 29 Value stored at the first index position is 20 Robert is: 20
How do I output a variable as it cycles through the while or for loop?
I thought I found a solution here - which seems to be a much simpler method:
http://www.tek-tips.com/viewthread.cfm?SQID=26410&SPID=434&page=1&CFID=71743089&CFTOKEN=83595008
but that doesn't work for me either....
I have been at this for 6 hours....man.
thanks for your patience... |
________________________________ mr_fitz |
|
|
|
mr_fitz
Junior WebHelper
Joined: 25 Jun 2002
Posts: 4
|
Posted:
Tue Jun 25, 2002 9:33 pm (21 years, 10 months ago) |
|
Thanks to Daniel's post...
I did get something to work which takes advantage of the LIMIT parameter in the mysql_query () command as follows (but there has to be a better way?):
# make a query on a table in my database
$query = "SELECT MOCi FROM mydatabase LIMIT 1, 3";
//the LIMIT specifies only one row of data from MOCi
//Robert = LIMIT 1
//Jamie = LIMIT 1, 1
//Timothy = LIMIT 1, 2
//Douglas = LIMIT 1, 3
//etc...luckily I have only 14 rows...for now...
//verify
$query_result_handle = mysql_query ($query) or die ('The query failed! table_name must be a valid table name that exists in the database specified in mysql_select_db');
// use mysql_fetch_row to retrieve the row's result
while ($row = mysql_fetch_row ($query_result_handle))
{
$membername=$row[0];
}
print "$membername";
?>
Outputs as follows:
43
Which is Douglas's MOCi score.
But this seems rather awkward. What if my mysql table gets reformatted? Isn't there a way to use the name field in combination with the MOCi field to output cell-at-a-time? |
________________________________ mr_fitz |
|
|
|
mr_fitz
Junior WebHelper
Joined: 25 Jun 2002
Posts: 4
|
Posted:
Tue Jun 25, 2002 11:29 pm (21 years, 10 months ago) |
|
This works:
<$
//query the database for a specific row of data
$sql_query = "SELECT * FROM mydatabase WHERE Name = 'Robert'";
//store the queried row in the variable: $result
$result = mysql_query($sql_query);
//get the actual data from the result set
$row = mysql_fetch_array($result);
//fill the $row[] array with a column to display for Name listed above
echo ($row[MOCi]);
?>
prints the cell's value:
51
(problem I had before was partially, Robert had to be in ' ': 'Robert' - since is a text field)
thanks again for the help
special thanks to help here from anonymous:
http://codewalkers.com/forum/index.php?action=displaythread&forum=phpcoding&id=265&realm=default |
________________________________ mr_fitz |
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.165155 seconds :: 19 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |