Jump to content


Photo

mysql simple query


  • Please log in to reply
4 replies to this topic

#1 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 06 October 2006 - 04:16 PM

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

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 October 2006 - 04:22 PM

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');
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 06 October 2006 - 04:48 PM

At the moment I have the following 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"; }
?>

But I can not understand why the variable $mysqlcode is not assigned. Do you know why? Thank you.

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 October 2006 - 04:58 PM

At the moment I have the following 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"; }
?>

But I can not understand why the variable $mysqlcode is not assigned. Do you know why? Thank you.

you may need to do some error checking. try this:
<?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');
?>

just make sure you have a record returned first
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 06 October 2006 - 05:16 PM

:) thank you.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users