Jump to content

mysql simple query


pedrobcabral

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.