Jump to content

[SOLVED] Can someone have a look at this for me please?


Mardoxx

Recommended Posts

id

name

1

Adam

2

Bill

 

<?php

$id_list_array = array(1,2);

			foreach ($id_list_array as $id_number) {
			echo "$id_number<br />";
				if ($row['id'] == $id_number)
				{
					echo $row['id'] . "<!!!>" . $row['name'] . "<!!!>added\n";
					break;
				} else {
					echo $row['id'] . "<!!!>" . $row['name'] . "<!!!>notadded\n";
					break;
				}
			}
?>

 

It just outputs this:

 

2<!!!>Bill<!!!>notadded

 

 

instead of

 

1<!!!>Adam<!!!>added

2<!!!>Bill<!!!>added

 

 

any ideas why?

 

thanks in advance!

or if anyone can think of a more efficient way of doing it I would be very grateful!

 

What ID is unique, and so are the ID's in the array

 

I can't think of a way of mayching them up other than checking each new row against the whole array.

 

anyone? :P

SELECT * FROM data

 

 

there's a csv list of data that has been selected posted to the php file this is then exploded to an array.

 

I want this php script to echo ALL the data but give a different output on the data that has an ID which is in the array. (also I want it done in one query if possible)

This should work

 

<?php
$id_array = array(1,2);

while($row = mysql_fetch_assoc($result)) {

  if (in_array($row['id'],$id_array)) {
    
echo $row['id'] . '<!!!>' . $row['name'] .'<!!!>added<br />';

  } else {
    
echo $row['id'] . "<!!!>" . $row['name'] . "<!!!>notadded<br />";

  }
  
}
?>

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.