Jump to content

[SOLVED] How to make a mysql_fetch_array results into array


otixz

Recommended Posts

Hi,

 

I have a msyql query here. How Can I make the query result into array?

 

$qry_course = mysql_query("select * from tblcourses where title IS NULL");
$row_course = mysql_num_rows($qry_course); 


				if($row_course=="0"){
				}
				else{						

						while($d = mysql_fetch_array($qry_course))	
						{	

					               //I want to make $d['coursename'] as an array.
							echo  $d['coursename'];

						}

                                       }

 

2.) also, I have another array named, $colorlist. My question is how can I create a query that can join the $colorList array and the $d['coursename'] array together in one query.

 

the query that  I want to produce is:

 

update tbl set color as $colorlist where course='$d['coursename']'; // Please remember that I have two array.

 

please help!

while($d = mysql_fetch_array($qry_course))	
{
$coursenames[] = $d['coursename']; // Adds $d['coursename'] into the $coursenames array
echo  $d['coursename'];
}

 

You just need to find out which index for both the $coursenames and $colorList arrays point to your desired values, then your query will just look like this:

"UPDATE tbl SET color = '{$colorlist[$colorIndex]}' where course='{$coursenames[$courseIndex]}'"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.