Page 1 of 1

Cant grab data from array for single ID but can for *

Posted: Sat Dec 18, 2004 4:44 pm
by nirus
The following works fine but when you try to search for a single record it fails. All I change is this line:

$result=mysql_query("SELECT * FROM contact ORDER BY name",$connect);
is changed to:
$result=mysql_query("SELECT * FROM contact WHERE id='$dwnstrmid'",$connect);

then of course I only show notes when displaying $result:
echo $myrow['notes'];

I think the proble may in how I am callling the query, but it works when I display all data and not just for $dwnstrmid.
while($myrow=mysql_fetch_assoc($result))

Code: Select all

include "header.php";
$result=mysql_query("SELECT * FROM contact ORDER BY name",$connect);
echo "<table>";
while($myrow=mysql_fetch_assoc($result))
      &#123;
      echo"<tr><td>";
      $myrow&#1111;'dwnstrmid'];
      echo $myrow&#1111;'notes'];
      echo "</td>";
// Print the options to Read, Edit & Delete the Downstreams
      echo "<td><a href="read_contact.php?dwnstrmid=$myrow&#1111;downstrmid]">Notes</a>
      || <a href="edit_contact.php?dwnstrmid=$myrow&#1111;dwnstrmid]">Edit</a>
      || <a href="delete_contact.php?dwnstrmid=$myrow&#1111;dwnstrmid"> Delete</a></font></td></tr>";
      &#125;
      echo "</table>";
?>
Any help would deserve a :D :D
- nirus

Posted: Sat Dec 18, 2004 4:49 pm
by markl999
You probably have register_globals Off (and rightly so) so you need to use:
$result=mysql_query("SELECT * FROM contact WHERE id='{$_GET['dwnstrmid']}'",$connect); as $dwnstrmid won't be set.

With register_globals Off, when you pass a value in the url, for example index.php?foo=66 then $foo won't be set. You need to access it using $_GET. The same applies to POST vars etc, see http://php.net/variables.predefined for more info.

Posted: Sat Dec 18, 2004 4:52 pm
by nirus
Yeah, I totaly I forgot about register globals and had issues elsewhere in my program where I had to POST. Thanks for reminding me.

-Nirus

thank you

Posted: Thu Dec 30, 2004 6:44 pm
by jasper
Just wanted to drop by and say thank you, this thread helped this newbie out so much. :lol: