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

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nirus
Forum Newbie
Posts: 16
Joined: Fri Dec 17, 2004 12:35 am
Location: Iowa

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

Post 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
Last edited by nirus on Sat Dec 18, 2004 4:49 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
nirus
Forum Newbie
Posts: 16
Joined: Fri Dec 17, 2004 12:35 am
Location: Iowa

Post 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
jasper
Forum Newbie
Posts: 3
Joined: Thu Dec 30, 2004 6:37 pm

thank you

Post by jasper »

Just wanted to drop by and say thank you, this thread helped this newbie out so much. :lol:
Post Reply