View Full Version : Resolved retrieve integer from database

Paul Williams
01-21-2012, 06:17 AM
Ok, here is how I fixed this issue.
If someone has this same struggle, then hopefully this will help.

My original post: Date 18 Jan 2012
Title : “getting data back from a php function”

Overview: from the browser, I was trying to “pluck” out an integer value from the database and bring that value back to the browser for further use.

Nomanic, and Old Pendant, were very helpful in aiding me.
Hats off, thank you.

Here is how the fix went:
Client-script code calls the server using Jquery $.get()
Server-script code calls the database and “plucks” out a value that I need, then echo() that value back to the calling statement.

Client-script code:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">


$('#mainContent a').click( function()

$.get('getStatus-server-script.php', {data:0}, processResponse);
function processResponse(data,status){
if (status == 'success') { statusIndex = data }
else { statusIndex = 'error' }
}; //end processResponse function
return false;

}); // end mainContent.click function

}); // end document.ready function


Server-script code:

mysql_select_db($database_connFtH, $connFtH);
$result = mysql_query("SELECT status_index FROM status_table ORDER BY row_id DESC");
$row_result = mysql_fetch_assoc($result);
$index = $row_result['status_index'];
echo "$index";

Short explaination:
the client-script code calls the server using Jqueary’s $.get() command
$.get('getStatus.php', {data:0}, processResponse);
function processResponse(data,status){ ………….. }
in order to get back an integer from the DB, I had to send out an integer {data:0} as an object literal. And then it worked great.

The server processed getStatus.php with no trouble and echo’d back the integer value that it retrieved from the DB, and a “success” string.

The server script code connects with the database and then SELECT’s the column where the data is, and brings the column of data back in DESC’ending order, so that the latest column entry will be first in line to be “plucked” out of there.
The next line grabs the field or column names, for easy access.
Finally the line $row_result[‘status_index’]; does the “plucking” and assigns $index the value of the latest DB entry. That easy.

Again, thank you Nomanic, and thank you Old Pendant.
Hopefully, someone will have this issue to solve and my fix will help them out.
Paul Williams