pedrobcabral Posted October 6, 2006 Share Posted October 6, 2006 $query = "SELECT FROM registar codigo WHERE email = '{$this->email}'";$result = mysql_query($query);while($row = mysql_fetch_object($result)) { $this->mysql_codigo = "$row->codigo"; }I know there is only one record, how can I skip the while thing?Thank you. Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 6, 2006 Share Posted October 6, 2006 code:[code]<?php$sql = mysql_query("SELECT * FROM myTable LIMIT 1"); // one record returned// either assign the entire row like this:$row = mysql_fetch_array($sql);// or touch individual items:$name = mysql_result($sql, 0, 'name');?>[/code] Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted October 6, 2006 Author Share Posted October 6, 2006 At the moment I have the following code:[code]<?php$query = "SELECT FROM register code WHERE email = '{$this->email}'";$result = mysql_query($query);while($row = mysql_fetch_object($result)) { $this->mysqlcode = "$row->code"; }?>[/code]But I can not understand why the variable $mysqlcode is not assigned. Do you know why? Thank you. Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 6, 2006 Share Posted October 6, 2006 [quote author=pedrobcabral link=topic=110707.msg448103#msg448103 date=1160153289]At the moment I have the following code:[code]<?php$query = "SELECT FROM register code WHERE email = '{$this->email}'";$result = mysql_query($query);while($row = mysql_fetch_object($result)) { $this->mysqlcode = "$row->code"; }?>[/code]But I can not understand why the variable $mysqlcode is not assigned. Do you know why? Thank you.[/quote]you may need to do some error checking. try this:[code]<?php$query = "SELECT FROM register code WHERE email = '{$this->email}'";$result = mysql_query($query);if (mysql_num_rows($result) == 1) $this->mysqlcode = mysql_result($sql, 0, 'code');?>[/code]just make sure you have a record returned first Quote Link to comment Share on other sites More sharing options...
pedrobcabral Posted October 6, 2006 Author Share Posted October 6, 2006 :) thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.