SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    variable inside queryName

    Code:
    $myQuery=mysql_query("select name from myTable1
    order by id") ; 
    
    while($row = mysql_fetch_array($myQuery) )
    {
    echo $row['name'];
    }
    The code above works fine.

    However, I like to use a variable inside queryName "$myQuery"
    So I made the trial code for it like the following.

    Code:
    $myVariable=1;
    
    ${myQuery$myVariable}=mysql_query("select name from myTable1
    order by id") ; 
    
    while($row = mysql_fetch_array(${myQuery$myVariable}) )
    {
    echo $row['name'];
    }
    But the trial code above causes "syntax error, unexpected T_VARIABLE".

    How can I put a variable inside queryName?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Variable variables.

    PHP Code:
    $queryname "myQuery".$yourvar;
    $
    $queryname mysql_query ..... 

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Variable variables.

    PHP Code:
    $queryname "myQuery".$yourvar;
    $
    $queryname mysql_query ..... 
    Thank you. it works fine.


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
  •