Jump to content

Archived

This topic is now archived and is closed to further replies.

pedrobcabral

mysql simple query

Recommended Posts

$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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.