Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    assign to variable

    I am trying to take data from the database and assign it to a variable but i'm not sure how
    this is the code ive been trying

    $sql = "SELECT Name FROM Names WHERE Name = 'Peter'";

    while($row = @mysql_fetch_array($sql))
    {
    $var == $row['Name'];
    }

    thanks

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $sql "SELECT Name FROM Names WHERE Name = 'Peter'";
    $query mysql_query($sql) or die(mysql_error());
    while(
    $row = @mysql_fetch_array($query))
    {
    $var $row['Name'];


  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,798
    Thanks
    19
    Thanked 156 Times in 147 Posts
    $sql = "SELECT Name FROM Names WHERE Name = 'Peter'";
    $result = mysql_query($sql);

    while ($row = mysql_fetch_assoc($result))
    {
    $var = $row['Name'];
    }
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by bunny1 View Post
    PHP Code:
    $sql "SELECT Name FROM Names WHERE Name = 'Peter'";

    while(
    $row = @mysql_fetch_array($sql))
    {
    $var == $row['Name'];

    Hey bunny! Remember that when you make a query to a DB, you've got to use mysql_query() to actually send the request. And, of course, make sure you're already connected to your database before you make a query.


  •  

    Posting Permissions

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