Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

more looping trouble 1

Status
Not open for further replies.

tippytarka

Programmer
Jul 19, 2004
115
GB
i'm a little lost with how to print all the elements of an array into a table cell. i'm using a 'for loop' to loop all the elements.

this query gives me the result.... one, two, three, four, (which is want i want)

Code:
for ($i = 0; $i < count($jobid); $i++) {
$query = "SELECT p1_job_title_code.job_title_01
		FROM p1_job_title_code 
		WHERE p1_job_title_code.job_title_id = '".$jobid[$i]."'";
$query_result = mysql_query($query);
$column = mysql_fetch_row($query_result);

$col = ''.$column[0].', ';

echo $col;
}

but when i place $col within the table cell (outside of the 'for loop') ...like in the following script, i get only a result of.... four, (and i want to avoid elements one, two, three, from being overwritten)

Code:
echo '<tr>';
echo '<td>JOB TITLES</td>';

for ($i = 0; $i < count($jobid); $i++) {
$query = "SELECT p1_job_title_code.job_title_01
		FROM p1_job_title_code 
		WHERE p1_job_title_code.job_title_id = '".$jobid[$i]."'";
$query_result = mysql_query($query);
$column = mysql_fetch_row($query_result);

$col = ''.$column[0].', ';
}

echo '<td>'.$col.'</td>';
echo '</tr>';

if i place the entire 'for loop' and query inside the echoed table cell i get an error message on the WHERE line in the query..

how on earth do i resolve this??
 
$col .= ''.$column[0].', ';

Code:
echo '<tr>';
echo '<td>JOB TITLES</td>';

for ($i = 0; $i < count($jobid); $i++) {
$query = "SELECT p1_job_title_code.job_title_01
        FROM p1_job_title_code 
        WHERE p1_job_title_code.job_title_id = '".$jobid[$i]."'";
$query_result = mysql_query($query);
$column = mysql_fetch_row($query_result);

$col .= ''.$column[0].', ';
}

echo '<td>'.$col.'</td>';
echo '</tr>';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top