SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PhP MySQL Query into Variables

    Is there a way to to change the echo of each ad into a different variable that I can echo out elsewhere?

    PHP Code:
        $a_query  "SELECT * 
            FROM ads
                WHERE site='this site' AND size='150x150' AND active='1' AND paying='1'
                    ORDER BY RAND()
                        LIMIT 
    $max_ads";
                    
        
    $a_result mysql_query($a_query) or die('Error, There are no Ads');
        while(
    $a_row mysql_fetch_array($a_result)){    
            
    $a_link $a_row['link'];
            
    $a_image $a_row['image'];
            
    $a_alt $a_row['alt'];    
            
    $a_type $a_row['type'];
            if(
    $a_type == "Event" || $a_type == "Site")    {$a_target=" target=\"_blank\"";}
                echo 
    " <a href=\"$a_link\" title=\"".$a_alt."\"".$a_target."><img src=\"http://$a_image\" alt=\"$a_alt\" width=\"150px\" height=\"150px\" border=\"0\"/></a>\n";    
            } 
    Like this?
    PHP Code:
    $variable[0] = " <a href=\"$a_link\" title=\"".$a_alt."\"".$a_target."><img src=\"http://$a_image\" alt=\"$a_alt\" width=\"150px\" height=\"150px\" border=\"0\"/></a>\n"

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Close.

    You can append values to an array like so
    PHP Code:
    $the_array[] = "foo";
    $the_array[] = "bar"
    http://www.php.net/manual/en/language.types.array.php

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not working but this is the idea I've had in mind.

    PHP Code:
    $i=1;
    while(
    $a_row mysql_fetch_array($a_result)){    
            
    $a_link $a_row['link'];
            
    $a_image $a_row['image'];
            
    $a_alt $a_row['alt'];    
            
    $a_type $a_row['type'];
            if(
    $a_type == "Event" || $a_type == "Site")    {$a_target=" target=\"_blank\"";}

            
    $adARRAY[$i] = " <a href=\"$a_link\" title=\"".$a_alt."\"".$a_target."><img src=\"http://$a_image\" alt=\"$a_alt\" width=\"150px\" height=\"150px\" border=\"0\"/></a>\n";    
            
    $i++;
            } 

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use the assignment operator(=)

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doh!


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
  •