I am creating my own snippets and plugins in modx to automate many functions on a website and wondered if there was a more elegant way to update and query the database.
I have it all working as I want it but wondered if I was doubling up on queries etc. A partial example is below and wondered if this is the right way to do things to fetch database values. Should I name each as $result1 $result2 etc... or is calling them all $result ok? Can I make the 2 results below in to one? I’m using the top $result just to get the appId value to put in the $result1 WHERE appID= is that necessary using a separate database query? I’m not sure if you can get values at the end of a script and place them at the start of the script?
$result = $modx->db->select("appId", "modx_apps" ) or die ("table not found");
if(mysql_num_rows($result) ) {
while($row = mysql_fetch_array($result)) {
extract($row);
$row['appId'];
$appId = $row['appId'];
}
}
//get appId and put the value in the result1 WHERE go get the correct tables...
$result1 = $modx->db->select("appId,tsDone", "modx_apps" , "appId=$appId") or die ("table not found");
if(mysql_num_rows($result1) > 0) {
while($row = mysql_fetch_array($result1)) {
extract($row);
$row['tsDone'];
$tsDone = $row['tsDone'];
if ($tsDone == 'done'){
echo "This account has been setup already.";
}
}
}
//END
Any simple pointers would be great, thanks!