-1

I need to get unique ID for each array element inside second array. That ID already exist in table but I cant get them separately. URL that am getting now looks like this: http://page.com/index.php?p=view&m=area&id=173id=552id=768id=36id=217id= I need just one ID and if first is used set second and so on. I know that I should use mysqli or PDO and normalized tables but that later, now I need help with this.

This is the code:

$res= mysql_query("SELECT * FROM area WHERE user='$user' ORDER BY date") or     die("Error: " . mysql_error());
while($row = mysql_fetch_assoc($res))
{
   $id = $row['id'];
   $x = array();
   $parent = array();
   foreach($row as $value)
   {
      if ($value == $id) continue;

      else if ($value == $user) continue;

      $result = explode(",", $value);

      foreach($result as $newvalue)
      {
         $query = "SELECT x,firm FROM list where list.x='$newvalue'";
         $result = mysql_query($query);
         $r = mysql_fetch_assoc($result);
         $x[] = $r['x'];
         $xx = implode("id=",$x);
         $parent[] = $r['firm'];
         $list = implode("<a href='index.php?p=view&m=area&$xx'>", $parent)."</a>";
      }
    }
echo "<td><span>" . $list . "</span>/td>";

}

Thank you

Rafael Azevedo
  • 330
  • 2
  • 8
jak
  • 7
  • 1
  • 5

2 Answers2

1

first of all

$list = implode("<a h

should be

$list .= implode("<a h
Ochi
  • 1,468
  • 12
  • 18
  • that exactly what you are doing - you are adding to $parent for every row you get from database - so maybe you also want to "$parent = array();" in the beginning of foreach and not before – Ochi Jun 05 '13 at 00:05
0

That URL syntax is not the correct way to pass an array of values to a PHP script. It should use PHP array syntax for the parameter names. Also, you need separate your parameters with an ampersand (&):

 http://page.com/index.php?p=view&m=area&id[]=173&id[]=552&id[]=76&8id[]=36&id[]=217

Then you can get the second one by using

$second_id = $_GET['id'][1]; // 552

etc.

FYI, you shouldn't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • i dont need second id. just first. rest need to be deleted, hidden or whatever – jak Jun 05 '13 at 00:00
  • we are thinking about different pages. i know how to get it but first i need to show it correctly. now it is: &id=173id=552id=768 but should be: http://page.com/index.php?p=view&m=area&id=173 and http://page.com/index.php?p=view&m=area&id=552 and so on. its multiple links on same page – jak Jun 05 '13 at 00:08