Posts by timmylogue

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

I remember when this community was busy. I feel like nobody replies anymore…

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

Any help it appreciated!

Does anyone know how to have the node put on top after <slideshow> every time. I think it’s called insertBefore. I can’t figure it out for the life of me. I know simpleXML doesn’t offer this. Found out the hard way!

Like this…
<slideshow>
<image id="3" src="image.jpg" desc="text" />
<image id="2" src="image.jpg" desc="text" />
<image id="1" src="image.jpg" desc="text" />
</slideshow>
My code:
$dom = new DOMDocument();
$dom->formatOutput = true;

$dom->load('myfile.xml');

$root = $dom->documentElement;
$newresult = $root->appendChild( $dom->createElement('image') );

$newresult->setAttribute('id', '1');
$newresult->setAttribute('src', 'image.jpg');
$newresult->setAttribute('desc', 'text');

//echo ''. $dom->saveXML() .'';
$dom->save('myfile.xml') or die('XML Manipulate Error');
332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

Crap..

I just realized I put this post on the wrong forum. Admins, is there any way you can move this to the ActiveDen forum?

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

I have a slideshow and it loads images from an XML file – Simply enough. I’m not an expect in AS3 but I can figure things out sometimes.

I need to add some code to http://pastie.org/10216820. What I need to add is, if there is only 1 image in the XML (images.xml) file, have it stop the slideshow from running anymore. Right now It keeps running the slideshow (starting over) even if only 1 image file in there.

I know an “if, else” statement would fix this.. right?

Thanks so much guys! :D

- Tim
332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says




>

This query is inefficient and it won’t use indexes, if any. As a rule of thumb, one should never use “NOT”, or “different from” in the comparison clauses. A more efficient version is the following:

SELECT * from TABLE WHERE registered < DATE_SUB(CURRENT_DATE(), INTERVAL 30 day)
First of all, it has nothing to do with indexes. :)

When you use SQL, it has always to do with indexes. Trust me on that, I’ve been a DBA for long enough.


Besides, I know of famous frameworks which allows the use of NOT in comparison clause. Or <> as per SQL-92 standard

The fact that they allow it doesn’t mean that it’s an optimal way of doing things. The ”<>” clause, in particular, is a performance killer and should always be replaced by a more efficient one. You will also find dozens of frameworks that compare dates using strings (e.g. SUBSTR(DATE(field), 4) = '20150414'), and that doesn’t make it a good practice (quite the opposite).

Another example is the method, that many people use even if they should not, of running a simple SELECT * FROM table and then using foreach in PHP to go through all the results and take the ones they want. That’s a terrible idea, especially when one nests queries in foreach loops (i.e. foreach…SELECT…foreach…SELECT). In the RDBMS world it’s called RBAR approach, and it’s frown upon (for a good reason).

Ah Jeez! Alright alright.. mate… I take my words back :)

Yes, pulling all and then doing via scripting language is the worst thing to do. However, since you are a DBA, may I have an opportunity to ask… At times, we want to implement a search engine (myisam based) which returns the results grouped by – alphabet-match first.. ordered alphabetically… however, if I want to push special characters at the bottom, (during ASC on the row)... I faced this issue last month and ran it past php to push the special characters based result at the bottom… For example, if ‘alpha’ is searched… it should return… alpha, alphabet, alpha-bet and not alpa,alpha-bet, alphabet. how could we achieve that using sql-only approach?




You can also do this with PHP. $sql = "SELECT * FROM yourtable"; $query = mysqli_query($dbconnectvariable, $sql);
Thank you!!

Hey!

If you could help me out with one more thing! How would I echo out the results for this? I guess I would use some loop too!

screenshot

I’m trying to display the “username(s)” of whoever has the value “expired” in their row. I have tired to Google some help before posting but I just can’t find out how to do this!

I was hoping this would work? I’m I close?

$result = mysql_query("SELECT * FROM users WHERE 'username'");
while ($row = mysql_fetch_array($result)) 
{
    $whoexpired = $row['trial_date_ended'];  
}

echo $whoexpired;

Thanks :)

And you see only the last username :) That is because you are ‘echo’-ing it outside the while loop, at each loop, $whoexpired is getting re-assigned based on the number of rows.

Make that:

$result = mysql_query("SELECT * FROM users WHERE 'username'");
while ($row = mysql_fetch_array($result)) 
{
    $whoexpired = $row['trial_date_ended'];  
    echo $whoexpired;
}
mysql_free_result($result);

Also, since I presume you are new and learning, dive into MySQLi rather mysql_ functions.. mysql_ functions are deprecated as of php 5.5 and will be removed for good…

Happy learning :)

Great! Thank you for all your help!

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says


$result = mysql_query("SELECT * FROM users");
while ($row = mysql_fetch_array($result)) {

    $whoexpired = $row['trial_date_ended'];  
    $user = $row['user'];
    $datenow = date("Y-m-d");

    if($datenow > $whoexpired){
        echo $user;
    }

}

This should do it, but you have to change your “trial_date”ended” field from DATETIME to DATE.

OR

If you need it as DATETIME, this should do it:


$result = mysql_query("SELECT * FROM users");
while ($row = mysql_fetch_array($result)) {

    $whoexpired = $row['trial_date_ended'];  
    $user = $row['user'];
    $datenow = date("Y-m-d H:i:s");

    if($datenow > $whoexpired){
        echo $user;
    }

}

Oops! Now I’ve seen that the “trial_date_ended” is “expired” or empty.

This should do it:
$result = mysql_query("SELECT * FROM users");
while ($row = mysql_fetch_array($result)) {

    $whoexpired = $row['trial_date_ended'];  
    $user = $row['user'];

    if($whoexpired == "expired"){
        echo $user;
    }

}

Thank you! :) Worked!

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

Hey KC, Thanks for all your help! Maybe you can help me out one last time? I’m having an issue with…

(My last post) http://codecanyon.net/forums/thread/php-mysql-check-if-any-dates-have-passed/171074?page=1&message_id=1250632#1250632

Any help is appreciated!

Thanks!

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says


You can also do this with PHP. $sql = "SELECT * FROM yourtable"; $query = mysqli_query($dbconnectvariable, $sql);
Thank you!!

Hey!

If you could help me out with one more thing! How would I echo out the results for this? I guess I would use some loop too!

screenshot

I’m trying to display the “username(s)” of whoever has the value “expired” in their row. I have tired to Google some help before posting but I just can’t find out how to do this!

I was hoping this would work? I’m I close?

$result = mysql_query("SELECT * FROM users WHERE 'username'");
while ($row = mysql_fetch_array($result)) 
{
    $whoexpired = $row['trial_date_ended'];  
}

echo $whoexpired;

Thanks :)

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

You can also do this with PHP. $sql = "SELECT * FROM yourtable"; $query = mysqli_query($dbconnectvariable, $sql); if($query){ while($row = mysqli_fetch_assoc($query)){ $date = $row['yourdatefield']; Inside the WHILE function, you can use $row to take each of the fields and pass them into variables, then email them to whatever email you want.

Thank you!!

332 posts
  • 8 Years of Membership
  • Collector Level 4
  • United States
timmylogue
says

Thank you! :)

by
by
by
by
by
by