Jump to content

[SOLVED] AJAX and Joomla


Edak

Recommended Posts

Hey everyone,

 

I have a page that currently shows entries from the last 30 days by default.

 

I currently have a link at the bottom. "Click here to show results past thirty days." and when clicked it will momentarily show the information I want, but almost instantly it will "reload" the page back to the last 30 days.

 

Now, I've had three people look at it (myself included) and it does this for me, the second person the link does nothing at all and for the last person the link takes them back to the main page.

 

I'm using Google Chrome, second person was using FireFox, not sure on the last.

 

http://jayandtonyservices.com/members/

 

user: test

pass: test

 

The page I'm referring to is "My Unlocks" currently there are two entries, one is set for the last 30 days (to show by default) and the second entry is set at a few months back (So you can see the difference).

 

Only real difference between the two PHP scripts is the MYSQL Query.

 

The PHP/JavaScript

<?php

define( '_VALID_MOS', 1 );

 

include_once( 'globals.php' );

require_once( 'configuration.php' );

require_once( 'includes/joomla.php' );

$option="test";

$mainframe = new mosMainFrame( $database, $option, '.' );

$mainframe->initSession();

$my = $mainframe->getUser();

$email = mysql_real_escape_string($my->email);

 

 

 

$con = mysql_connect("REMOVED","REMOVED","REMOVED") or die('Could not connect: ' . mysql_error());

mysql_select_db("jayandt_a4804327reselle", $con); //Replace with your MySQL DB Name

 

$sql = "SELECT * FROM unlock_pending WHERE payer_email = '$email' AND TO_DAYS(NOW()) - TO_DAYS(date) <= 30 ORDER BY date DESC";

 

$result = @mysql_query($sql);

?>

<html>

<body>

 

<script type="text/javascript">

var xmlhttp

 

function unlockpending()

{

xmlhttp=GetXmlHttpObject();

if (xmlhttp==null)

  {

  alert ("Your browser does not support XMLHTTP!");

  return;

  }

var url="unlockpending.php";

xmlhttp.onreadystatechange=stateChanged;

xmlhttp.open("POST",url,false);

xmlhttp.send(null);

}

 

function stateChanged()

{

if (xmlhttp.readyState==4)

  {

  document.getElementById("tableness").innerHTML=xmlhttp.responseText;

  }

}

 

function GetXmlHttpObject()

{

if (window.XMLHttpRequest)

  {

  // code for IE7+, Firefox, Chrome, Opera, Safari

  return new XMLHttpRequest();

  }

if (window.ActiveXObject)

  {

  // code for IE6, IE5

  return new ActiveXObject("Microsoft.XMLHTTP");

  }

return null;

}

</script>

 

<table border="0" cellspacing="0" cellpadding="2" id="tableness">

<tr>

<th align="left" width="75"><font face="Arial, Helvetica, sans-serif">Order#</font></th>

<th align="left" width="150"><font face="Arial, Helvetica, sans-serif">IMEI#</font></th>

<th align="left" width="100"><font face="Arial, Helvetica, sans-serif">Method</font></th>

<th align="center" width="70"><font face="Arial, Helvetica, sans-serif">Credits</font></th>

<th align="right" width="100"><font face="Arial, Helvetica, sans-serif">Unlock Code</font></th>

</tr>

 

<?php

 

while ($row = mysql_fetch_assoc($result))

{

if($row['unlockcode'] == "not found")

{

$color="red";

}

elseif ($row['unlockcode'] == "pending")

{

$color="gray";

}

else

{

$color="green";

}

?>

            <tr>

            <td align="left" width="75"><font face="Arial, Helvetica, sans-serif"><?php echo $row[ 'orderid']; ?></font></td>

            <td align="left" width="150"><font face="Arial, Helvetica, sans-serif"><?php echo $row['imei']; ?></font></td>

            <td align="left" width="100"><font face="Arial, Helvetica, sans-serif"><?php echo $row['method']; ?></font></td>

            <td align="center" width="70"><font face="Arial, Helvetica, sans-serif" color="red"><?php echo $row['creditded']; ?></font></td>

            <td align="right" width="100"><font face="Arial, Helvetica, sans-serif" color=<?php echo $color; ?>><?php echo $row['unlockcode']; ?></font></td>

            </tr>

 

<?php

}

mysql_free_result($result);

mysql_close($con);

?>

</tr>

</table>

<a href="" onclick="unlockpending()">Click here to show results past thirty days</a>

</body>

</html>

 

The PHP Script

<?php

define( '_VALID_MOS', 1 );

 

include_once( 'globals.php' );

require_once( 'configuration.php' );

require_once( 'includes/joomla.php' );

$option="test";

$mainframe = new mosMainFrame( $database, $option, '.' );

$mainframe->initSession();

$my = $mainframe->getUser();

$email = mysql_real_escape_string($my->email);

 

 

 

$con = mysql_connect("REMOVED","REMOVED","REMOVED") or die('Could not connect: ' . mysql_error());

mysql_select_db("jayandt_a4804327reselle", $con); //Replace with your MySQL DB Name

 

$sql = "SELECT * FROM unlock_pending WHERE payer_email = '$email' ORDER BY date DESC";

 

$result = @mysql_query($sql);

?>

<html>

<body>

 

<table border="0" cellspacing="0" cellpadding="2">

<tr>

<th align="left" width="75"><font face="Arial, Helvetica, sans-serif">Order#</font></th>

<th align="left" width="150"><font face="Arial, Helvetica, sans-serif">IMEI#</font></th>

<th align="left" width="100"><font face="Arial, Helvetica, sans-serif">Method</font></th>

<th align="center" width="70"><font face="Arial, Helvetica, sans-serif">Credits</font></th>

<th align="right" width="100"><font face="Arial, Helvetica, sans-serif">Unlock Code</font></th>

</tr>

 

<?php

 

while ($row = mysql_fetch_assoc($result))

{

if($row['unlockcode'] == "not found")

{

$color="red";

}

elseif ($row['unlockcode'] == "pending")

{

$color="gray";

}

else

{

$color="green";

}

?>

            <tr>

            <td align="left" width="75"><font face="Arial, Helvetica, sans-serif"><?php echo $row[ 'orderid']; ?></font></td>

            <td align="left" width="150"><font face="Arial, Helvetica, sans-serif"><?php echo $row['imei']; ?></font></td>

            <td align="left" width="100"><font face="Arial, Helvetica, sans-serif"><?php echo $row['method']; ?></font></td>

            <td align="center" width="70"><font face="Arial, Helvetica, sans-serif" color="red"><?php echo $row['creditded']; ?></font></td>

            <td align="right" width="100"><font face="Arial, Helvetica, sans-serif" color=<?php echo $color; ?>><?php echo $row['unlockcode']; ?></font></td>

            </tr>

 

<?php

}

mysql_free_result($result);

mysql_close($con);

?>

</tr>

</table>

</body>

</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.