Icy Phoenix

     
 


Post new topic  Reply to topic 
Page 1 of 1
 
 
Reply with quote Download Post 
Post How To Add Db Variable To A CONSTANT 
 
Fella's, I can't find anything on the WEB and it's driving me nuts!  

I have this constant and a Db query var attached to it - like so ->

U_GAME_LINK.$ID

and I want to use just the constant without the $ID because I want to be able to switch it with some other data?

This is what I currently have.

Code: [Download] [Hide] [Select]
define("U_GAME_LINK", "".DIR_PATH."index.php?action=play&ID=");


But This -> ID=$ID added to it doesn't work no matter how I try to qualify it and just keeps coming back empty!  

Question: Can it be done?

This is the whole section so that you can see where I'm coming from and why the question - Because IF I ever add SEO the CONSTANT will need to hold the SEO string instead?


Code: [Download] [Hide] [Select]
        $stmt = $database->prepare("SELECT ID FROM " . GAMES_TABLE . " WHERE active=1 ORDER BY RAND() LIMIT 50");
            $stmt->execute();
                $result = $stmt->fetchAll();
                    foreach($result as $row)
                {

                $ID = intval($row['ID']);

                    if(empty($row)){/*Do Nothing*/}else{

        echo'<url>
            <loc>'.cleanMAP(U_GAME_LINK.$ID).'</loc>
            <changefreq>always</changefreq>
            <priority>0.8</priority>
            </url>';
        }
    }

 



 
mortSend private message  
Back to topPage bottom
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us
 
Reply with quote Download Post 
Post Re: How To Add Db Variable To A CONSTANT 
 
Yes. It's mostly correct.

One note: your $ID = ... should be in the else (also, I tend not to use empty ifs... Just negate the condition).
It should work. However, I'd recommend you to use sprintf() instead of just appending to it.
 




____________
IcyPhoenix ADR RPGEzArena (modded phpBB2+ADR)
 
InformproSend private message  
Back to topPage bottom
Reply with quote Download Post 
Post Re: How To Add Db Variable To A CONSTANT 
 
Can't use the ID in both because of this very rough example which would hopefully use the same constant and be switched in the "CONSTANTS" file.php.

Code: [Download] [Hide] [Select]
    if($seo == 1){
            $play = ''.DIR_PATH. '/play/'.$row['ID'].'-'.$name.'.html';
        } else {
            $play = ''. DIR_PATH. '/index.php?action=play&amp;ID=' . $ID;
        }


This is the style I intend to use to build it.

Code: [Download] [Hide] [Select]
    if($seo == 1){

    define("U_MOST_PLAYED", "".DOMAIN."mostplayed/");
BLAH!

    }else{

    define("U_MOST_PLAYED", "".DOMAIN."index.php?action=most_played");
BLAH!

}


And I'm not sure what you mean by use sprintf( as I'm using PDO in the sitemap - as a learning curve to convert the whole thing?



Quote:
I tend not to use empty ifs


I don't know, people have so many different ideas about almost everything with php  

I'm sure that if I ran it somewhere else, someone would tell me that I haven't checked if the Db is empty - which previously (at least with mySQL) would throw up errors and arguments and freeze everything up?

 
 



 
mortSend private message  
Back to topPage bottom
Post new topic  Reply to topic  Page 1 of 1
 


Display posts from previous:    

HideWas this topic useful?

Link this topic
URL
BBCode
HTML




 
Permissions List
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events


  

 

  cron