Jump to content

sql advice.


xyn

Recommended Posts

right, I know using queries like:
SELECT x,y FROM tbl WHERE field='Value'

but I was wondering if this is correct:

[code=php:0]include "db.php";
$zql = mysql_query("SELECT mem_mail FROM accounts WHERE id='$act'");
while( $data = mysql_fetch_row($zql))
{
$emaillz = $data['mem_mail'];
}[/code]
Link to comment
Share on other sites

I'f you're trying to create an array then NO because $emaillz will only contain the last record selected from the table, you would need this

[code]include "db.php";
$zql = mysql_query("SELECT mem_mail FROM accounts WHERE id='$act'");
while( $data = mysql_fetch_array($zql)){
$emaillz[] = $data['mem_mail'];
}[/code]

Then to echo out all the record further down the page you would need to use somthing like this..

[code]foreach ($emaillz as $email) {
echo('Email Address: '.$email);
}[/code]

If there is only 1 record to be returned then might as well just use

[code]$zql = mysql_query("SELECT mem_mail FROM accounts WHERE id='$act'");
$data = mysql_fetch_array($zql);
$emaillz = $data['mem_mail'];

As you don't need to loop thru the data as only 1 record will ever be returned.

[/code]
Regards
Liam
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.