Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translate attempt 1

Status
Not open for further replies.

kensington45

Technical User
Jun 26, 2008
9
0
0
I have something working great in PHP but now I need to move something over to a server without PHP and am trying to translate the PHP script into Java.

PHP:
Code:
if(isset($_GET['getClientId'])){  
  $res = mysql_query("select * from tableOne where clientID='".$_GET['getClientId']."'") or die(mysql_error());
  if($inf = mysql_fetch_array($res)

...

My attempt in Java and it is giving me errors with getClientId part and lost in fetching array part. Please advise any corrections I need?
Code:
//db connection part here...

try {
String res = "";
if(getParameter("getClientId")) {
   res = stmt.executeQuery("select * from tableOne where clientID='" + getParameter("getClientId") + "');
  
String $inf []; 
if($inf.equals(getParameterValues($res)) {

....
 
shouldn't you be asking this in the java forum?

 
I really am lost on some of the PHP terminology..

What is isset...google says its a session variable??
if(isset($_GET['getClientId'])){

mysql_fetch_array is fetching parameters that are taken from array??
if($inf = mysql_fetch_array($res)
 
isset is a function that checks to see whether a variable is set.

So in your example, if $_GET['getclientId'] is set then do something.


mysql_fetch_array is a function from the mysql library used to retrieve the results from a query to the database.
In every call it retrieves a single row from the results and returns it as an array, where each field of the row is in an array key.


I strongly suggest you use the php online manual here:
Just use the search field at the top and put in the name of the function you want to find.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks,

The return from this ($inf = mysql_fetch_array($res) looks like this:
Code:
$inf["firstname"]    
$inf["lastname"]   
$inf["address"]

I assume this translates to?
Code:
0 = firstname   
1 = lastname  
3 = address


 
It means that the contents of the field of a table from the database named firstname is in the "firstname" key of the array.

if you were to do :
echo "$inf['firstname']";

You would get a value such as "John"

Now Java could probably return the information for the database in a numbered array or something different.

If your table is say:

Firstname lastname address age birthday SSnumber hair color.
John Smith 234 street 25 12/12/87 1251452 brown


When using the mysql_fetch_array I could simply do
echo "$inf['firstname'] , $inf['SSnumber']";

While if they were to be returned numbered sequentially.
SSnumber would probably be located in the 6th key.

It references a field in a table not necessarily a position in the array.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Kensington45: the php manual is amongst the best written and maintained example I have come across in the universe of language references. i highly commend it to you. Had you read the relevant excerpts (taken you a few minutes), you would most definitely have discovered the answers to your questions.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top