I dont know whether I am being completely stupid or what, but I cant seem to pick out all the records from my database.
The overall problem is:
I have a table with n amount of rows, and would like to pull all these rows out and store them in an array in php.
What I have so far is:
myquery=SELECT * FROM Table1;
result=mysql_fetch_array(myquery){
$skill1=$row['skill1']
$skill2=$row['skill2']
.....
this will store skill1 and skill2, but what if i have n skills? I have tried using the loop but im not sure if i did it correctly because I still had to state the variables in my array. If i have 8 variables, 8 skills will show and so on.
Can anyone help?
How to Use LOOP to get All the data from tables
Moderator: General Moderators
-
nishmgopal
- Forum Contributor
- Posts: 101
- Joined: Tue Mar 03, 2009 9:38 am
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: How to Use LOOP to get All the data from tables
If you have columns called skill1, skill2, etc in your table, then n must be fixed anyway.... and it means that you haven't normalised your tables properly.
However, to answer your query about storing in an array
$skills = array();
$skills[]=$row['skill1']
$skills[]=$row['skill2']
...
However, to answer your query about storing in an array
$skills = array();
$skills[]=$row['skill1']
$skills[]=$row['skill2']
...
-
nishmgopal
- Forum Contributor
- Posts: 101
- Joined: Tue Mar 03, 2009 9:38 am
Re: How to Use LOOP to get All the data from tables
Thank you, but what values goes into the square brackets:
$skill[]=$row['skill1];
sorry if it is a dumb question, but i am quiet new to programmin.
$skill[]=$row['skill1];
sorry if it is a dumb question, but i am quiet new to programmin.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: How to Use LOOP to get All the data from tables
No value goes in the square brackets.nishmgopal wrote:Thank you, but what values goes into the square brackets:
This is basically telling PHP to create a new element at the end of the current array, and populate it with the appropriate value.