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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post

    assigning a variable with a database value

    how do i connect to a mysql database and set a variable to equal a row value in a mysql db?

    i tried

    PHP Code:
    <?php
    $aa 
    mysql_connect("localhost""""");
          
    $db mysql_select_db("whmx_store",$aa);
          
    $sql_select "SELECT * FROM cds top1 ORDER BY dateofentry DESC LIMIT 1";
          
    $result mysql_query($sql_select) or die ("Queryproblem: " mysql_error());
                  while (
    $row mysql_fetch_array($result)) {        
                        
    $asin $row[8];
                        }
                            
    ?>
    but when i insert the $asin in something, it just shows up on the page as '$asin'

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $aa mysql_connect("localhost""""");
    $db mysql_select_db("whmx_store",$aa);
    $sql_select "SELECT [i]columnname[/i] FROM cds ORDER BY dateofentry DESC LIMIT 1";
    $result mysql_query($sql_select) or die ("Queryproblem: " mysql_error());
    if (
    mysql_num_rows($result)== 0){
        
    $echo ('<strong>No rows found.</strong>') ;
    } else {
        
    $row mysql_fetch_assoc($result) ;
        
    mysql_free_result($result);
        
    $asin $row['[i]columnname[/i]'];

    Loose the top1 --> it's the buggy JetSQL version of Limit1 etcetc
    http://www.codingforums.com/showthre...y&pagenumber=1

    I suppose you are after the last inserted record? --> Check the sticky on top of the mySQL forum.


  •  

    Posting Permissions

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