Page 1 of 1

Can someone whos good with php help me...

Posted: Mon Jun 16, 2003 5:11 pm
by I3lade
How would i use SELECT syntax to select a specific users data and post it like it would say:
Welcome <USERNAME>!
how do i do that, i know i have to get thier id and stuff but how? Please help.

Posted: Mon Jun 16, 2003 5:39 pm
by I3lade
Please some help here?

Posted: Mon Jun 16, 2003 6:05 pm
by Galahad
Let's say you select just the name from the database. You do something like:

Code: Select all

<?php
$row = mysql_fetch_row($query, $db);
?>
Then you do something like:

Code: Select all

<?php
echo "Welcome ".$row['0'];
?>
You may want to have a look at the mysql_fetch_* commands. Hope that helps.

Posted: Mon Jun 16, 2003 6:09 pm
by I3lade
Oh thanks, only i replace $row['0']; with $row['username']
and where do i put the row that says my user id?

Posted: Mon Jun 16, 2003 6:28 pm
by Galahad
What do you want to do with the id? Maybe something like:

Code: Select all

<?php
echo "Welcome ".$row['username']; 
echo "Your ID is ".$row['id'];
?>

Posted: Mon Jun 16, 2003 6:48 pm
by I3lade
So i do:

Code: Select all

<?php 
$row = mysql_fetch_row($query, $zeopets); 
?> 
<?php 
echo "Welcome ".$row&#1111;'username']; 
echo "Your ID is ".$row&#1111;'id']; 
?>
Like that?

Posted: Mon Jun 16, 2003 6:54 pm
by I3lade
Wait what do i put in $query?

Posted: Mon Jun 16, 2003 8:03 pm
by McGruff
mysql_fetch_row returns a numerical array: use mysql_fetch_assoc or mysql_fetch_array if you want to refer to the $row['keyname'].

Sounds like you need a manual from mysql.com - syntax etc is all in there.

I think you're looking for:

SELECT column1, column2, etc FROM table WHERE columnx='$value'

Posted: Tue Jun 17, 2003 2:53 pm
by I3lade
So far i have:
<?
mysql_connect("localhost","bladegames", "****");
mysql_select_db("bladegames");
$query = mysql_query("SELECT * FROM members where userid = '$user_id'");
{
echo "
Logged in as: $row[username] <br>";
}
?>
Where does the fetch code go?

Posted: Tue Jun 17, 2003 5:39 pm
by McGruff
$query = mysql_query("SELECT * FROM members where userid = '$user_id'");
$row = mysql_fetch_array($query);

Posted: Wed Jun 18, 2003 2:08 pm
by I3lade
<?
mysql_connect("localhost","bladegames", "****");
mysql_select_db("bladegames");
$query = mysql_query("SELECT * FROM members where userid = '$user_id'");
$row = mysql_fetch_array($query);
{
echo "
Logged in as: $row[username] <br>";
}
?>
like that?

Posted: Wed Jun 18, 2003 9:31 pm
by McGruff
Yes - but always enclose keynames in single quotes:

$row['username']

Posted: Thu Jun 19, 2003 4:18 am
by twigletmac
Unless you're in a double quoted string because:

Code: Select all

echo "Logged in as: $row['username'] <br>";
will give you a parse error (or an undefined index notice depending which version of PHP you've got).

Code: Select all

echo "Logged in as: $row[username] <br>";
is fine.

Mac