Page 1 of 1

going true the whole table

Posted: Thu Aug 05, 2004 8:46 pm
by ol4pr0
Oke this sounds a little dumb maby, why putting mails in somany rows ( well i have actually a reason for that )

but what i am trying to do now is to find a email going true all these fields
i have email untill email24 field.
however i do not get any results neither do i get a error.

Code: Select all

for ($i=1;$i<=24;$i++)
$query = 'SELECT email'.$i.' FROM email WHERE email'.$i.'="'.$_POST ['check'].'"';
#using SELECT id FROM... works but if there are duplicate emails it only
#returns one id.. i need them all 
$result = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($result)) {
	echo $row['id'];
}
}

Posted: Thu Aug 05, 2004 10:12 pm
by feyd
8O you have 24 fields dedicated to email in this table? You seriously need to rethink your table structure.. yikes..

The code you posted will only search the database for email24.. $row will never contain 'id' because you didn't select it.

Posted: Thu Aug 05, 2004 10:15 pm
by ol4pr0
yea i know, however i got lots and i mean lots of mails lol. (meaning thousands)

Any ideas on how i can archive this?

Posted: Thu Aug 05, 2004 10:20 pm
by Joe
Could you not just use something like:

Code: Select all

$query = "SELECT * FROM email";
$result = mysql_query($query) or die(mysql_error());

while(true)
{
 $row = mysql_fetch_assoc($result);
 if ($row == false) break;
 echo $row['id'];
}
in order to view the id's?

Posted: Thu Aug 05, 2004 10:34 pm
by ol4pr0
Becuase there are many ids.. and i need the id that belongs to the email so i can find it lots and lots faster.

Re: going true the whole table

Posted: Fri Aug 06, 2004 12:18 am
by timvw
ol4pr0 wrote:
but what i am trying to do now is to find a email going true all these fields
i have email untill email24 field.
however i do not get any results neither do i get a error.

Code: Select all

for ($i=1;$i<=24;$i++)
$query = 'SELECT email'.$i.' FROM email WHERE email'.$i.'="'.$_POST ['check'].'"';
#using SELECT id FROM... works but if there are duplicate emails it only
#returns one id.. i need them all 
$result = mysql_query($query) or die (mysql_error());
while($row = mysql_fetch_array($result)) {
	echo $row['id'];
}
}
Meaby i don't understand what you are trying to do, but if i do, this would be how i do it:

Code: Select all

// cleanup input
$post = mysql_escape_string($_POST['check']);

// build query
$query = 'SELECT * FROM email WHERE ';
for ($i=1;$i<=24;$i++)
{
	$query.= 'email' . $i . "='" . $post . ' OR ';
}
$query .= '1=1';

$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($row))
{
	print_r($row);
}

Posted: Fri Aug 06, 2004 12:30 am
by feyd
:? wouldn't that grab every row?

Posted: Fri Aug 06, 2004 12:44 pm
by ol4pr0

Code: Select all

$query = 'SELECT * FROM email WHERE ';
for ($i=1;$i<=24;$i++)
{
   $query.= 'email' . $i . '="' . $post . '" OR ';
}
$query .= '1=1';

$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($row))
{
   print_r($row);
} 
}
Had to alter it a little bit., but it actually cant execute it
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

Posted: Fri Aug 06, 2004 1:07 pm
by feyd
mysql_fetch_assoc($result)

Posted: Fri Aug 06, 2004 1:15 pm
by Joe
Hmm I wonder why you were using $row instead of $result :O

Posted: Fri Aug 06, 2004 3:44 pm
by ol4pr0
Lol. must of been late last night

Joe: I am wondering that 2 hahaha..

timvw: sorry br0 that didnt go well, as feyd said "would'nt that grab every row?" ( yes it will )
But it does not get me the right id.

However it might be useful somehow, i am not sure how, There must be a way i can substract the information i need from that array ? wouldnt there.

meaning

output ej:
[email6] => somemail@somedomain.com

What can i use to get the [email6] and somemail@domein.com part

This does get me somwhere i think but, maby someone can help me getting it the way it should

Code: Select all

if (in_array($_POST['check'], $row))
	{
	echo 'fount it<P>';
	print_r($row);
	}
	else
	{
	echo '<br>Not found';
	}