request data from mysql to assign them to variables??? how to do

Discussion in 'MySQL' started by rymdoll, Sep 5, 2008.

  1. #1
    i have a mysql database containing a table called configuration
    in this table i have my rows, one of them for example is Adsense
    i want a query that gets all data from this table to let me assign them to variables that i will later use on my website.
    i tried this but didnt work :
    <?php
     $cnx=mysql_connect($server, $username , $password);
     mysql_select_db($base) 
        or die("Database not found.");
    
    
    $sqlRequete = "select * from configuration";
    $qryRequete = mysql_query($sqlRequete,$cnx);
    $foRequete = mysql_fetch_object($qryRequete);
    while($qryRequete)
    {
    print($foRequete->Adsense);
    $adsense=($foRequete->Adsense);
    $foRequete = mysql_fetch_object($qryRequete);
    } 
    
    mysql_close();
    ?>
    
    
    
    <script type="text/javascript"><!--
    google_ad_client = "$adsense";
    google_ad_width = 250;
    google_ad_height = 250;
    google_ad_format = "250x250_as";
    google_ad_type = "text_image";
    google_ad_channel = "";
    google_color_border = "20395B";
    google_color_bg = "FFFFFF";
    google_color_link = "20395B";
    google_color_text = "FFFFFF";
    google_color_url = "FFFFFF";
    google_ui_features = "rc:10";
    //-->
    </script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    Code (markup):

     
    rymdoll, Sep 5, 2008 IP
  2. iRakic

    iRakic Member

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Try

    Change line:
    google_ad_client = "$adsense";
    Code (markup):
    Into:
    google_ad_client = "<?php echo  $adsense ?>";
    Code (markup):
    I guess you need only one adsense result from DB, in that case you need to remove while loop. If you want random adsense selection from DB, use MySQL RAND function.

    BTW Don't use SQL's "SELECT *" if you don't need ;)

    Edit: I have notice that this is in DB forum, I think this need to be moved into PHP forum.
     
    iRakic, Sep 5, 2008 IP
    rymdoll likes this.
  3. rymdoll

    rymdoll Banned

    Messages:
    182
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thank you very much, it helped me,
    this solved the hardest part in my script ;)
    i will ask for more help later if i get bugs :)
    reputation added
     
    rymdoll, Sep 6, 2008 IP
  4. iRakic

    iRakic Member

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    np man, I'm here to help ;)
     
    iRakic, Sep 6, 2008 IP