View Full Version : MySQL-PHP Question
riegiepoo
02-08-2004, 07:56 PM
I dont have any php-nerd friends to ask, and I couldn't find anything too usefull on the 'net about it, since I'm a super n00b at mysql (and pretty much php)
So, heres the problem:
This is the code I have at the moment (well, part of it)
$result = mysql_query("select user_nickname, user_description FROM $tableusers ORDER BY user_nickname ASC");
Now, I dont want everything from those colums to be echo-ed. Is there a way to only fetch a certain row? or maybe hide the other data coming out?
Thanks0rz
And, is there a good site or a book someone could recommend? (for lerning php). php.net just doesnt do it for me.
Side note: I am posting a thread.
Scott
02-08-2004, 11:05 PM
'Sup? Heidi said you needed help.
The easiest thing to do is assign each value from the column to a variable.
You'd do that like this:
$result = mysql_query("select user_nickname, user_description FROM $tableusers ORDER BY user_nickname ASC");
//get the data from $result
while($row = mysql_fetch_array($result))
{
$nickname = $row['user_nickname'];
$description = $row['user_description'];
echo $nickname . '<br />' . $description;
}
That echos both. Delete whichever one you don't want echoed.
This code assumes you've connected to mysql earlier in the page.
To make youe code more readable, you might want to consider keeping your actual query in another variable, say $sql, and calling mysql_query() on $sql.
I learned php and mysql by downloading phpbb and figuring out how it worked. Another thing you might look at is w3schools.com
[s]
riegiepoo
02-09-2004, 12:06 AM
heres basicly the entire code
function whoareyou() {
global $wpdb, $tableusers; //this conects to the database and such
$result = mysql_query("select user_nickname, user_description FROM $tableusers ORDER BY user_nickname ASC");
echo "<ul>\n";
while(list($user, $what) = mysql_fetch_row($result)) {
echo "<li><strong>$user:</strong> ";
if (empty($what)) {
echo "No bio yet.</li>\n";
} else {
echo "$what</li>\n";
}
}
echo "</ul>\n";
}
So, each user has an ID. And I was just wondering how to get one certain ID at a time.
(the list thing may seem useless, but I have other meanings for it)
Im so n00bie, its great. :-[
But thank you very much for atleast replying and trying to help :)
Scott
02-09-2004, 12:14 AM
If each user has an ID, where are you seleccting that? You need the WHERE clause.
You might want this bit of sql:
SELECT user_nickname, user_description FROM $tableusers WHERE user_id = $user_id LIMIT 1;
I don't know what you call your user id column in your database, but that would go where I typed "user_id". You'd want to pass the value of $user_id to the function.
[s]
riegiepoo
02-09-2004, 01:03 AM
Hooray! its working now! Thank you very very very much!
You da' man!
Scott
02-09-2004, 01:15 AM
No problem. Glad you got it all sorted out.
[s]
vBulletin v3.5.3, Copyright ©2000-2006, Jelsoft Enterprises Ltd.