Jump to content

Archived

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

xyn

sql advice.

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]

Share this post


Link to post
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

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.