What I am trying to do is show a small widget on the home page to let a user know when their membership expires. Here is my current code
$subExpire = Engine_Api::_()->getDbtable('subscriptions', 'payment');
$db2 = $streamTable->getAdapter();
$stmt2 = $db2->query("select * from engine4_payment_subscriptions where `user_id`='$user_id'");
$arr2 = $stmt2->fetch();
if ($arr2['expiration_date']=="NULL")
{
$exp = "NEVER";
}
echo $exp;
I think the major issue has to do with Engine_Api::_()->getDbtable('subscriptions', 'payment');
Ultimately once it comes back with a date I would like to calculate how many days left in the membership from the current date.
Any suggestions?
PS, $user_id is defined and does return a numeric value
One more thing, the actual table name is engine4_payment_subscriptions
That´s a strange way of making the query in social engine, try this:
$table = Engine_Api::_()->getDbtable('subscriptions', 'payment');
$select = $table->select()->where('user_id = ?', $user_id);
$arr2 = $table->fetchAll($select);
if ($arr2['expiration_date']=="NULL")
{
$exp = "NEVER";
}
echo $exp;
Related
This is my first year with HTML, PHP, JAVASCRIPT and mysql!
And i am having a problem, im making a website that users can only see them products.
For example: Admin created a product for MARTA, when MARTA log in she can see her product.
I have created the table USER_EQUIPMENT but i don't know how can i use it like i want.
I made something like this:
function getEquipment($name)
{
$query = "select * from equipments where name = '$name'";
$this->connect();
$res = $this->execute($query);
$this->disconnect();
return $res;
}
and then i called it like:
$name = $_SESSION['name'];
include_once('DataAccess.php');
$da = new DataAccess();
$res = $da->getEquipment($name);
But i doesn't get the equipment by the name.
Little help please?
Thanks.
i am trying to create a golf tourney scoreboard where i input the scores from each round and if i put in what course was played, it will go into the row of my sql database. how do i make a total score that is figured out in my php code go into a row that i specify on the form?
the form is built out like this:
<input name='name/handi/par/course/hole1/etc' type='text'>
to save space/time just short-handing the coding as much as possible. the php looks like this:
$name = $_POST['name/handi/par/course/hole1/etc'];
then i have the math broken out to figure the front 9, back 9, total score (with handicap [handi] worked in)
$totOut = ($hole1 + $hole2...etc)
$totIn = ($hole10 + $hole11 ... etc)
$total = ($totOut + $totIn) - $handi;
$o_u_total = $total - $par; (over/under for the week)
$o_u_today = $total - $par; (over/under for the day)
the total for today (b/c there are 4 rounds) and the total for the whole week. the totals for the whole week are worked out in a query on the display page:
$sql = "SELECT name,
SUM(total) AS Score,
SUM(o_u_total) AS Over_Under,
total AS Total_Today,
o_u_today AS Over_Under_Today
FROM matchplay
GROUP BY name
ORDER BY Score ASC";
$result = mysqli_query($conn, $sql);
and how i am trying to make the inputted value (course name) go into the specific row (designated in my sql dbase) is like this:
$ridge;
if ($_POST['course'] = 'The Ridge') {
($ridge = $total);
}
$cove;
if ($_POST['course'] = 'The Cove') {
($cove = $total);
} etc
i have a feeling that i am doing something terribly wrong with the if/else, but i don't know how else to choose what i want the $total to go into.
can anybody help me?
i figured it out ... thanks if anybody saw it and was in the middle of thumping me on the head with how easy it was
$ridge;
if ($_POST['course'] == 'The Ridge') {
($ridge = $total);
}
and not
$ridge;
if ($_POST['course'] = 'The Ridge') {
($ridge = $total);
}
Glad you did figure it out. To enhance your code and avoid multiple ifs, you can use a switch case statement.
$course_name = $_POST['course'];
switch($course_name){
case ('The Ridge'):
// your code here
break;
case ('The code'):
// an other code here
break;
}
Hope this help.
I can list the users that have relations of a current user, but how do I list users that don't have relations with the current user. Or how do I exclude users that have relations with the current user from a list. I am happy to see it in javascript, ios etc..
$user = ParseUser::getCurrentUser();
$relation = $user->getRelation("follow");
$usersFollowed = $relation->getQuery()->find();
print_r($usersFollowed);
Thanks
I'm not using php, but you could try to use notEqualTo constraint to 'follow' with current user.
Something like query.notEqualTo('follow', Parse.User.current()); in js
I have found a work around to achieve what I wanted to achieve. I am happy for others to improve it.
$user = ParseUser::getCurrentUser();
$relation = $user->getRelation("follow");
$usersFollowed = $relation->getQuery()->find();
// loop through all the users that are being followed
for ($i = 0; $i < count($usersFollowed); $i++) {
$object = $usersFollowed[$i];
$usernames = $object->get('username');
// concatenate the usernames to produce a string
$str_usernames .= $usernames . ' ';
}
// convert the string into an array
$array_usernames = explode(" ", $str_usernames);
print_r($array_usernames);
echo "<br><br>";
// query all the usernames not contained in the above array
$query = new ParseQuery("_User");
$query->notContainedIn("username", $array_usernames);
$results = $query->find();
print_r($results);
I hope this helps others, it costs two api requests. I am not sure how it would perform over thousands or hundreds of thousands of usernames though.
apologize firstly for my questionable coding in php/mysql however this is all self taught (possibly not best practice)
All my code seems to work , however when the results are written to the page any $dxcall that is not in the $qrzdata database gets filled with the last result all other data displays fine. I have tried changing the like $dxcall to = $dxcall. I have also tried combining the fetch arrays too incase my issues was there too. But clearly my code does not know how to handle where there is not data match in the qrzdata database and to move on.
$frqry is the main data, all the other mysql_query's be it the $squares and $qrzdata are matching what comes from $frqry. Hope this makes sense !!
Here is my code
$frqry = mysql_query("select * from spots where freq between '69900' and '70300' ORDER BY datetime desc limit 30");
While ($r0 = mysql_fetch_array($frqry))
{
$freq = $r0["freq"];
$dxcall = $r0["dxcall"];
$datetime = $r0["datetime"];
$comments = $r0["comments"];
$spotter = $r0["spotter"];
$dt = date('d-m-y H:i ', $datetime);
$qra = $r0["loc"];
$squares = mysql_query("select * from squares where callsign like '$dxcall' limit 1");
while ($r1 = mysql_fetch_array($squares))
{
$qra = $r1["loc"];
}
$qrzdata = mysql_query("select * from qrzdata where callsign = '".$dxcall."' limit 1");
While ($r2 = mysql_fetch_array($qrzdata))
{
$country = $r2["country"];
$firstname = $r2["firstname"];
$city = $r2["city"];
}
Any help is greatly appreciated. Thank you.
You need to learn about the power of the JOIN ;)
Your whole code could be rewritten in one single query :
disclaimer: not tested, but you certainly get the idea
SELECT * FROM spots
JOIN squares ON (squares.callsign = spots.dxcall) -- this comes in stead of your first inner loop
JOIN qrzdata ON (qrzdata.callsign = spots.dxcall) -- this is your second loop
WHERE freq BETWEEN 69900 AND 70300 -- remove quotes, you are dealing with integers, not strings (hopefully)
You have to reset your vars!
While ($r0 = mysql_fetch_array($frqry))
{
$qra = '';
$country = '';
$firstname = '';
$city = '';
or you will allways get the last value
I am trying to write a program of photoalbums in simple PHP, but i want to make it a little more advanced then i used to do.
Usually i wrote it like this:
<?php $query = mysql_query("SELECT year FROM photo");
while($record = mysql_fetch_object($query)) {
echo $record->year."<br>";
$query2 = mysql_query("SELECT albumName, url FROM photo WHERE year = '".$year."'");
while($album = mysql_fetch_object($query2)){
echo "".$albumName."<br>";
}
} ?>
As you would understand it's really bad to have two while loops in one, so i want to do it differently. I want to learn how to do this better. The thing is, I don't know a name for this so it's difficult to search on this subject. Is there anyone able to hand me a snippet of code, a source or something to get me on the way?
Thank you so much.
You could do
<?php
$year = ''; // create a generic variable that will hold the album year
$query = mysql_query("SELECT albumName, url, year FROM photo ORDER BY year"); // Sort by year
while($album = mysql_fetch_object($query)) {
if($album->year != $year){ // check if $album->year is the same as the $year value
echo $album->year."<br>"; // if not the same echo the year
}
$year = $album->year; // set the $year value to the $album->year
echo "".$album->albumName."<br>";
}
?>
What if you do this:
<?php $query = mysql_query("SELECT albumName, url, year FROM photo");
while($record = mysql_fetch_object($query)) {
echo $record->year."<br>";
echo "".$albumName."<br>";
}
?>
What would be wrong?
Now your code might produce an album more than one times, if there are many albums per year.