Jump to content

help with query


pro_se

Recommended Posts

I have a query that is looking up a users comments:
[code]<?php
  $uname = $_GET['name'];
$result = mysql_query("select * from comments where to=$uname");
while($r = mysql_fetch_array($result))
{
  $from=$r["from"];
  $msg=$r["msg"];
  $time=$r["time"];
  $date=$r["date"];
  echo "$msg<br />
      <sub>$from | $date | $time</sub>
      <hr color=#B0B0B0 noshade=noshade size=1/>";
}
?>[/code]

and I keep getting an error like this: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/user.php on line 45

I have no idea what is wrong... maybe someone can help me?
Link to comment
https://forums.phpfreaks.com/topic/15865-help-with-query/
Share on other sites

try this ok.
[code]
<?php

$uname = $_GET['name'];
$query="select * from comments where to='$uname'";
$result=mysql_query($query);

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

   $from=$r["from"];
   $msg=$r["msg"];
   $time=$r["time"];
   $date=$r["date"];
   echo "$msg<br />
   <sub>$from | $date | $time</sub>
   <hr color=#B0B0B0 noshade=noshade size=1/>";
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15865-help-with-query/#findComment-65051
Share on other sites

post your findings ok.
[code]
<?php

$uname = $_GET['name'];
$query="select * from comments where uname='$uname'";

print_r($query);

$result=mysql_query($query);

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

   $from=$r["from"];
   $msg=$r["msg"];
   $time=$r["time"];
   $date=$r["date"];
   echo "$msg<br />
   <sub>$from | $date | $time</sub>
   <hr color=#B0B0B0 noshade=noshade size=1/>";
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15865-help-with-query/#findComment-65053
Share on other sites

id  to    from          ip                    msg                                  date        time
1 corey Nil Thacker 10.160.43.200 Testing the comment system... July 28, 2006 1:03

in a table called comments...

my address bar looks like: http://localhost/users.php?name=corey
Link to comment
https://forums.phpfreaks.com/topic/15865-help-with-query/#findComment-65057
Share on other sites

add ip=ip in the link ok

post the findings

[code]
<?php
$ip = $_GET['ip'];
$uname = $_GET['name'];
$query="select * from comments where uname='$uname' and ip='$ip'";

print_r($query);

$result=mysql_query($query);

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

   $from=$r["from"];
   $msg=$r["msg"];
   $time=$r["time"];
   $date=$r["date"];
   echo "$msg<br />
   <sub>$from | $date | $time</sub>
   <hr color=#B0B0B0 noshade=noshade size=1/>";
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15865-help-with-query/#findComment-65061
Share on other sites

try this for a min ok see if we can get somthink out lol ...........
[code]
<?php

$uname = $_GET['name'];
$query="select * from comments where uname='$uname''";

print_r($query);

$result=mysql_query($query);

while(list($key,$val)=each($result)) {

echo "$key  : $val ";

}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15865-help-with-query/#findComment-65065
Share on other sites

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.