How To Add Db Variable To A CONSTANT »  Show posts from    to     

Icy Phoenix


English Chit Chat - How To Add Db Variable To A CONSTANT



mort [ Fri 19 Dec, 2014 23:28 ]
Post subject: 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: [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: [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>';
}
}


Informpro [ Sat 20 Dec, 2014 00:15 ]
Post subject: 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.


mort [ Sat 20 Dec, 2014 01:09 ]
Post subject: 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: [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: [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?





Powered by Icy Phoenix