Jump to content

[SOLVED] Newbie question, problem with mysql_fetch_array


Fhwoarang

Recommended Posts

Hi, everybody. I recently started to with with PHP5 and I'm kinda liking it.

 

However, as usual, I'm having some troubles, and this time is about MySQL.

 

I use mysql_fetch_array to convert into an array a given query. I don't know why, but if I do this:

 

SELECT * FROM table WHERE GivenField = "GivenText";

 

If my table has 5 couls, I get a size 10 ten array, I mean, it doubles my array with null or blank spaces, I don't know why. So I have to use mysql_fetch_row instead, which works fine.

 

Now, I want this table to be printed on a HTML table, but I want to exclude the first row in the table (which contains each field's name). I was reading that when you use:

 

$row = mysql_fetch_array();

 

You can print it with something like this:

 

while ($row=mysql_fetch_array())
{
$row[Field1]
$row[Field2]
}

 

Do I have to use "=" or "==" for " $row=mysql_fetch_array()" inside the "while"? It still works if I just use only one "=".

 

When I use:

"echo "$row[Field1];

 

It prints the name of the field on the first iteration, it doesn't skip it (and the goes through the next rows). What am I doing wrong or what's the best way to do this? Seems like a very common task.

 

Thanks in advice. ;D

Link to comment
Share on other sites

fetch_row gives you a numerically index array

fetch_assoc gives array indexed by fieldnames

fetch_array (default arguments) gives array containing both.

 

You can add an optional second arg to fetch_array to give either numeric or associative indexed array (but then IMO you may as well use one of the other two functions).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.