Source language: Translate to:

PHP Question...

Questions and information about creating Internet aware NeoBook applications. Including PHP, HTML, FTP, HTTP, Email, etc.

Moderator: Neosoft Support

PHP Question...

Postby David de Argentina » Wed Nov 25, 2009 4:13 pm

Hi all,

I don't know much about PHP.

I'm trying to do a process that connect to a database, add 1 to a record, and get one field value of one record as link.

I did this code

Code: Select all
<?
$user_ID = $_REQUEST['user_ID'];

$link = mysql_connect('localhost', 'My_UserID', 'My_Pass') or die('Could not connect: ' . mysql_error());

mysql_select_db('My_Database') or die('Could not select database');

$query = "UPDATE My_Table SET Acum=Acum+1 WHERE Id = $user_ID";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$query = "SELECT Redir FROM My_Table where Id = $user_ID";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
 { foreach ($line as $col_value)
 {     $Enlace = "$col_value"; }
}

mysql_free_result($result);
mysql_close($link);
header("location:$Enlace");
?>


Where:
user_ID is the ID or the record
Redir is the field who has the link where the webbrowser must be redirected.
$Enlace is the variable to store the redir value

In fact, this function works, but I think do a loop to catch an only one value... is not ellegant...

Does any know a better way to do this ?

Thanks in advance,
David de Argentina
User avatar
David de Argentina
 
Posts: 1562
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Postby smartmedia » Thu Nov 26, 2009 12:21 pm

Hi..

You can limit the results of your SELECT if you are sure that this will return only 1 user. So, then you don't need the while, just pass the result to your variable..
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Postby bunker » Fri Nov 27, 2009 8:51 am

Hi, there is the code.
Code: Select all
<?
$user_ID = $_REQUEST['user_ID'];

$link = mysql_connect('localhost', 'My_UserID', 'My_Pass') or die('Could not connect: ' . mysql_error());

mysql_select_db('My_Database') or die('Could not select database');

$query = "UPDATE My_Table SET Acum=Acum+1 WHERE Id = $user_ID";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$query = "SELECT Redir FROM My_Table where Id = $user_ID";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$Enlace = mysql_result($result,0,0);

mysql_free_result($result);
mysql_close($link);
header("location:$Enlace");
?>


Greetings
User avatar
bunker
 
Posts: 141
Joined: Sat Sep 29, 2007 4:00 pm

Postby Ferdari » Mon Dec 14, 2009 8:34 pm

i have a program made with NeoBook, it works with php and mysql see it working at www.eulerion.com , any question about a function ask.

Saludos! :lol:
Ferdari
 
Posts: 32
Joined: Sun Sep 13, 2009 9:34 pm

Postby David de Argentina » Thu Dec 17, 2009 1:44 pm

Thanks SmartMedia & Bunker

I discovered the function mysql_fetch_row().

It is exactly I need.

Greetings from Buenos Aires,
David de Argentina
User avatar
David de Argentina
 
Posts: 1562
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina


Return to NeoBook and the Internet

Who is online

Users browsing this forum: No registered users and 1 guest