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. Link to comment https://forums.phpfreaks.com/topic/23189-mysql-simple-query/ 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] Link to comment https://forums.phpfreaks.com/topic/23189-mysql-simple-query/#findComment-105112 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. Link to comment https://forums.phpfreaks.com/topic/23189-mysql-simple-query/#findComment-105129 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 Link to comment https://forums.phpfreaks.com/topic/23189-mysql-simple-query/#findComment-105137 Share on other sites More sharing options...
pedrobcabral Posted October 6, 2006 Author Share Posted October 6, 2006 :) thank you. Link to comment https://forums.phpfreaks.com/topic/23189-mysql-simple-query/#findComment-105152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.