472,958 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

2 short mysql/php questions

Hi there,

I have two short questions:

1st:
I have a site with a mysql DB. There are 3 admins.
They're stored in a table called "admin".
Fields in there are 'id','name','passw'.
If i use the following query: "SELECT * FROM admin";
It returns three rows. How can i print out e.g. of the second
returned row the password. It has to be something like the following:
$query_results[2]['passw'];

2nd:
Is there a way to manipulate data in fields of a mysql DB. Now there is
data that is partially upercase, though all of it should be lowercase.
is there something like: LOWERCASE 'name' FROM 'members'
(i know this doesn't exist, butyou know what i mean..)

Thanks in advance.

Jul 17 '05 #1
8 1974
*** frizzle escribió/wrote (24 Mar 2005 09:42:42 -0800):
If i use the following query: "SELECT * FROM admin";
It returns three rows. How can i print out e.g. of the second
returned row the password. It has to be something like the following:
$query_results[2]['passw'];
You need to use mysql_connect(), mysql_select_db(), mysql_query() and
mysql_fetch_assoc(). In their manual pages you can find usage examples.

Is there a way to manipulate data in fields of a mysql DB. Now there is
data that is partially upercase, though all of it should be lowercase.
is there something like: LOWERCASE 'name' FROM 'members'
(i know this doesn't exist, butyou know what i mean..)


In www.mysql.com you have an online manual with all the operators and
functions. The string functions are here:

http://dev.mysql.com/doc/mysql/en/string-functions.html

However, the way you built your fictious example makes me thing that this
is your first contact with relational databases. I'd recommend that you
follow a tutorial to learn basic SQL. It doesn't need to be MySQL-specific.
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Jul 17 '05 #2
I'm sorry, but maybe i've been incomplete with providing information:
I know how to get the information from the database. Usually with e.g.
a guestbook i use

do{
blah
}while($result = mysql_fetch_array($get_results));

But instead of this, i'd like to replace this method with the above i
mentioned.

Both questions are not about the same example, if that's what you mean
with relational databses, I am quite new to mySQL, and also
(less but still) quite new to PHP as you've probably noticed.

If i've missed out something, i'm sorry, just want to make things more
clear...

Greetings!

Jul 17 '05 #3
*** frizzle escribió/wrote (24 Mar 2005 15:34:52 -0800):
Usually with e.g. a guestbook i use

do{
blah
}while($result = mysql_fetch_array($get_results));
What does the do{} block do in the first iteration, when $result still
doesn't have any value?

But instead of this, i'd like to replace this method with the above i
mentioned.


Just use a counter variable. Give it an initial value and increment it in
each iteration. A simple if() can tell you if you reached the desired row.

Also, please note the order of rows is absolutely meaningless unless you
have an ORDER BY clause.

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Jul 17 '05 #4
I'm not sure if i understood it correctly, but i've solved it like
this:

$get_admins = mysql_query("SELECT id,username,email,website FROM admin
ORDER BY id",$db);
$admins = mysql_fetch_array($get_admins);

do{

if($admins['id']==1)
{
$admin1_username= $admins['username'];
$admin1_email = $admins['email'];
$admin1_website = $admins['website'];
}
else if($admins['id']==2)
{
$admin2_username= $admins['username'];
$admin2_email = $admins['email'];
$admin2_website = $admins['website'];
}
else if($admins['id']==3)
{
$admin3_username= $admins['username'];
$admin3_email = $admins['email'];
$admin3_website = $admins['website'];
};

}while($admins = mysql_fetch_array($get_admins));
It works, but somehow i feel like i'm missing out something. I wonder
how i'd do this if i had hundreds of admins: i can't imagine i'd have
to define the properties for each admin...

Well, anyway it works!

Thanks for that.

I can't figure out my second question though: i only find ways to
manipulate the output of a query, instead of manipulating the actual
raw data inside the DB..

Greetings frizzle.

Jul 17 '05 #5


frizzle wrote:
I'm not sure if i understood it correctly, but i've solved it like
this:

$get_admins = mysql_query("SELECT id,username,email,website FROM admin
ORDER BY id",$db);
$admins = mysql_fetch_array($get_admins);

do{

if($admins['id']==1)
{
$admin1_username= $admins['username'];
$admin1_email = $admins['email'];
$admin1_website = $admins['website'];
}
else if($admins['id']==2)
{
$admin2_username= $admins['username'];
$admin2_email = $admins['email'];
$admin2_website = $admins['website'];
}
else if($admins['id']==3)
{
$admin3_username= $admins['username'];
$admin3_email = $admins['email'];
$admin3_website = $admins['website'];
};

}while($admins = mysql_fetch_array($get_admins));
It works, but somehow i feel like i'm missing out something. I wonder
how i'd do this if i had hundreds of admins: i can't imagine i'd have
to define the properties for each admin...

Well, anyway it works!

Thanks for that.

I can't figure out my second question though: i only find ways to
manipulate the output of a query, instead of manipulating the actual
raw data inside the DB..

Greetings frizzle.


Why not something like (not tested):

$admins = array();
while ($data = mysql_fetch_array($get_admins)) {
$admins[$data['id']] = array('username'=>$data['username'],
'email'=>$data['email'],
'website'->$data['website']);
}

This will place the data in

$admins[1]['username']
$admins[1]['email']
$admins[1]['website']
$admins[2]['username']

etc.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #6
Great Jerry

That's just what i meant! Just great. I got it working immediatly.
I even belive that now the number corresponds with the id, instead of
it's position in the array... is that correct?
In that case, it's even greater than great!

You made my day!

Jul 17 '05 #7


frizzle wrote:
Great Jerry

That's just what i meant! Just great. I got it working immediatly.
I even belive that now the number corresponds with the id, instead of
it's position in the array... is that correct?
In that case, it's even greater than great!

You made my day!

Yes, the index of the item in the array matches the id.

Glad to be of help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #8
Very very nice work! :D

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chris | last post by:
Hi, sorry to post OT but i cant find the MySQL newsgroup, however i am hoping to pick up on some expert advice from php/mysql gurus here. I'm having some trouble performing a delete across two...
7
by: varois83 | last post by:
Hi I am fairly new to PHP/mysql and was reading an online tutorial and learned that my short tags weren't enabled. At this time I have no need for them, my setup apache/mysql/php runs on my PC...
0
by: Harald Falkenberg | last post by:
Hi, I'm new to mysql. Coming from the oracle database a couple of questions came up. Perhaps somebody, who has also experience in oracle, can set me on the tracks. Questions: 1. is mysql...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
3
by: Try Kret | last post by:
Hello, Any good documents on how to connect and manipulate data stored in MySQL. Faithfully yours, Try.
1
by: E.T. Grey | last post by:
Hi All, Despite spending the past six to seven hours perusing the docs on the mySQl site, I still have questions unanswered, and have been unable to get any help. I am familiar with Sybase, some...
0
by: Sam Flywheel | last post by:
Hello, all: I am pleased to announce that the MySQL Journal is moving forward. During the past two weeks, I've been discussing the journal with MySQL AB, and the plan that's been devised...
10
by: bill | last post by:
I have a database of kennels. One page lists the kennels alphabetically by kennel name. I have a field for kennel name and an index with kennel name as the only field. Some of the kennels have...
27
by: gerrymcc | last post by:
Hello, I'm a php/mysql beginner... Is there any way of making the mysql command line client full-screen? Sometimes it's easier to use the client than go thru php, but since it's only about 80...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.