NeoSoft Support Forum Forum Index  Your source for Plug-Ins, sample publications, source code and more...

Source Language:
Translate to:

NeoSoft Support Forum
NeoSoft Community Support Forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   SmartFeedSmartFeed   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PHP Question...

 
Post new topic   printer-friendly view   Reply to topic    NeoSoft Support Forum Forum Index -> NeoBook and the Internet
View previous topic :: View next topic  
Author Message
David de Argentina
NeoBooker


Joined: 04 Apr 2005
Posts: 930
Location: Buenos Aires, Argentina

PostPosted: Wed Nov 25, 2009 4:13 pm    Post subject: PHP Question... Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
smartmedia
NeoBooker


Joined: 01 Apr 2005
Posts: 853
Location: Hellas

PostPosted: Thu Nov 26, 2009 12:21 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
bunker
NeoBooker


Joined: 29 Sep 2007
Posts: 111

PostPosted: Fri Nov 27, 2009 8:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Ferdari
NeoBooker


Joined: 13 Sep 2009
Posts: 12

PostPosted: Mon Dec 14, 2009 8:34 pm    Post subject: Reply with quote

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! Laughing
Back to top
View user's profile Send private message MSN Messenger
David de Argentina
NeoBooker


Joined: 04 Apr 2005
Posts: 930
Location: Buenos Aires, Argentina

PostPosted: Thu Dec 17, 2009 1:44 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    NeoSoft Support Forum Forum Index -> NeoBook and the Internet All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

Forum content © 2008 NeoSoft Corp. All rights reserved.