Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Aug 05, 2004 8:46 pm
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'];
}
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 05, 2004 10:12 pm
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.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Aug 05, 2004 10:15 pm
yea i know, however i got lots and i mean lots of mails lol. (meaning thousands)
Any ideas on how i can archive this?
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Thu Aug 05, 2004 10:20 pm
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?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Thu Aug 05, 2004 10:34 pm
Becuase there are many ids.. and i need the id that belongs to the email so i can find it lots and lots faster.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Fri Aug 06, 2004 12:18 am
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);
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 06, 2004 12:30 am
wouldn't that grab every row?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Aug 06, 2004 12:44 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 06, 2004 1:07 pm
mysql_fetch_assoc($result)
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Fri Aug 06, 2004 1:15 pm
Hmm I wonder why you were using $row instead of $result :O
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Aug 06, 2004 3:44 pm
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';
}