| View previous topic :: View next topic |
| Author |
Message |
David de Argentina NeoBooker

Joined: 04 Apr 2005 Posts: 930 Location: Buenos Aires, Argentina
|
Posted: Wed Nov 25, 2009 4:13 pm Post subject: PHP Question... |
|
|
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: | <?
$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 |
|
| Back to top |
|
 |
smartmedia NeoBooker

Joined: 01 Apr 2005 Posts: 853 Location: Hellas
|
Posted: Thu Nov 26, 2009 12:21 pm Post subject: |
|
|
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.. _________________ www.infogate.gr
www.rapidfinder.ws |
|
| Back to top |
|
 |
bunker NeoBooker

Joined: 29 Sep 2007 Posts: 111
|
Posted: Fri Nov 27, 2009 8:51 am Post subject: |
|
|
Hi, there is the code.
| Code: |
<?
$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 _________________
NeoBooKeRoS.CoM.aR |
|
| Back to top |
|
 |
Ferdari NeoBooker
Joined: 13 Sep 2009 Posts: 12
|
Posted: Mon Dec 14, 2009 8:34 pm Post subject: |
|
|
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!  |
|
| Back to top |
|
 |
David de Argentina NeoBooker

Joined: 04 Apr 2005 Posts: 930 Location: Buenos Aires, Argentina
|
Posted: Thu Dec 17, 2009 1:44 pm Post subject: |
|
|
Thanks SmartMedia & Bunker
I discovered the function mysql_fetch_row().
It is exactly I need.
Greetings from Buenos Aires,
David de Argentina |
|
| Back to top |
|
 |
|