Jump to content


Photo

sql advice.


  • Please log in to reply
2 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 14 July 2006 - 10:10 AM

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

but I was wondering if this is correct:

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


#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 14 July 2006 - 10:11 AM

yeap

#3 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 14 July 2006 - 11:54 AM

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

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

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

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

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

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

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users