Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

some problem to add a mysql field value to an array
how can i read a mysql table of two fields and test if the first field has a
value then add the second value to an array

I try this but it doesn't works

while ($row=mysql_fetch_array($result))
{
for ($i=0; $i< mysql_num_fields($result); $i++)
if ($row['CampoChiave']=='true')
$TempArray[ ]=$row['NomeCampo'];
}



Report this thread to moderator Post Follow-up to this message
Old Post
SAN CAZIANO
12-26-04 01:55 PM


Re: some problem to add a mysql field value to an array
What is the "for" loop for if you do not use it's index ($i)?

You are testing if CampoChiave has a string value of 'true'.
You wrote that you want to test if it has any value. You
may do it like this:

if (isset($row['CampoChiave']) && ($row['CampoChiave']!=''))
$TempArray[]=$row['NomeCampo'];


Hilarion

PS.: I do not use MySQL, so my suggestions are general PHP related
and may not be sufficient.



Report this thread to moderator Post Follow-up to this message
Old Post
Hilarion
12-26-04 01:55 PM


Re: some problem to add a mysql field value to an array
SAN CAZIANO wrote:
> how can i read a mysql table of two fields and test if the first field has
 a
> value then add the second value to an array
>
> I try this but it doesn't works
>
>  while ($row=mysql_fetch_array($result))
>  {
>    for ($i=0; $i< mysql_num_fields($result); $i++)
>   if ($row['CampoChiave']=='true')
>    $TempArray[ ]=$row['NomeCampo'];
>  }
>
>

Hi,

* Use mysql_fetch_assoc(), not mysql_fetch_array().

* You don't need the for loop that tests agains mysql_num_fields()

* It's generally more efficient if your CampoChiave takes integer values
1 and 0, rather than string values "true" and "false".

So:

===== START PHP CODE =====

while ($row = mysql_fetch_assoc($result))
{
if ($row["CampoChiave"])
{
$TempArray[] = $row["NomeCampo"];
}
}

====== END PHP CODE ======

Hope this helps,
Oli

Report this thread to moderator Post Follow-up to this message
Old Post
Oli Filth
12-26-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:23 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.