SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_result() function

    Hello,

    I want the following mysql_query to be executed:

    $username = mysql_query(
    "SELECT name from categories, users WHERE CID = categories.ID AND username = '$uid'");


    In the above example i want to display the category that belongs to each user, i do this by selecting the "name" that is a column inside the table "categories" and which contains the name of all categories, "users" is another table which contains all users, CID and username are columns inside the "users" table. As you may see, i already have the user id stored in the $uid variable.

    Well, that query should output just one value to the $username variable right? so in order to display it, i wouldn't need the function mysql_fetch_array() i think since it's just one value, but i don't know how to use the mysql_result() function, because this function only saves the data of one column and in this case i have used several columns to retrieve just one value.

    I couldn't do something like: mysql_result($username) because it outputs an error.

    I could use something like:

    $email = mysql_result($username,0,"emails");

    <?php
    your e-mail is <?=$email?>.
    ?>

    But that's only if the column "emails" was inside the "users" table. I hope i make sense.

    Thanks in advance.

    Toly
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine

  2. #2
    Victory shall be mine tubedogg's Avatar
    Join Date
    Mar 2001
    Location
    Medina, OH
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, rewrite your query for clarity:
    $username = mysql_query("SELECT categories.name FROM categories,users WHERE CID = categories.ID AND users.username='$uid'");
    Second, where is CID coming from? Column of the categories or the users table?
    Third, you are not selecting the email address column. So how are you planning to use it later?
    $username = mysql_query("SELECT categories.name,user.email FROM categories,users WHERE CID=categories.ID AND users.username='$uid'");
    Then just use mysql_result to get that stuff:
    $name = mysql_result($username,0,0);
    $email = mysql_result($username,0,1);
    Kevin

  3. #3
    Free your mind Toly's Avatar
    Join Date
    Sep 2001
    Location
    Panama
    Posts
    2,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply.

    I think i didn't explain myself clearly, sorry.

    The column CID belongs to the users table and basically contains numbers related to the ID's of the table categories, that's why i specify Mysql that CID must be equal to categories.ID.

    The e-mail thing was just an example of how i get to work the mysql_result() function if i was to select something from just one column, nothing more, that's why i didn't include it in the mysql_query thing.

    Anyways, i use the code you gave me and i still get the same error, the variable $name should output the value in html through php right? but i get the following error or someting like that:

    I write in my code:
    your name is <?=$name?>

    in the html page i get:

    your name is Resource id#10

    and don't know what this means, any idea?
    Last edited by Toly; Oct 26, 2001 at 05:33.
    Community Guidelines | Community FAQ

    "He that is kind is free, though he is a slave;
    he that is evil is a slave, though he be a king." - St. Augustine


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •