Jump to content

[SOLVED] select question


onthespot

Recommended Posts

Ok sorry im using a session variable in the username place, just replaced it here because I thought would be easier to just say i was using username!

 

<?

$showcomment=mysql_query("SELECT comment FROM ".TBL_COMMENTS." WHERE touser LIKE ".$requserinfo['username']."");

mysql_fetch_assoc($showcomment);

?>

 

This doesnt work, im just confused about how to get it to show that sql query. Any ideas?

Link to comment
Share on other sites

and this is my preference, but i HATE concatanation! (so much i cant even spell it!)

 

instead of

 


<?
$showcomment=mysql_query("SELECT comment FROM ".TBL_COMMENTS." WHERE touser LIKE ".$requserinfo['username']."");
mysql_fetch_assoc($showcomment);
?>

[/php

i'd do 

[code=php:0]

<?

$likematch=$requserinfo['username'];

$res=mysql_query("SELECT comment FROM TBL_COMMENTS WHERE touser LIKE '$likematch'");
$row=mysql_fetch_assoc($res);
$comment=$row[0];

?>

Link to comment
Share on other sites

$likematch=$req_user_info['username'];

 

$res=mysql_query("SELECT comment FROM ".TBL_COMMENTS." WHERE touser LIKE '$likematch'");

$row=mysql_fetch_assoc($res);

$comment=$row[0];

 

Used that and it doesnt work unfortunately, no errors, just nothing comes back on the webpage?

 

Whats the $comment=$row[0] do?

Link to comment
Share on other sites

$likematch= $req_user_info['username'];

 

$res=mysql_query("SELECT comment FROM ".TBL_COMMENTS." WHERE touser LIKE '$likematch'");

$row=mysql_fetch_assoc($res);

$comment=$row['comment'];

 

ok so thats what i have and there is nothing being returned.

 

In my database got primary key comment id, touser, fromuser, comment, commentdate. I have successfully got the inputting into the database working, but this is what i now cant do.

 

 

Link to comment
Share on other sites

lmao

 

had to run to the store for tomato paste and toothpaste!

 

also, try putting absolute values into your query, such as a working touser, then run it in the sql tab of phpmyadmin and make sure there are results to be got.

 

and dont get upset and assume we've abandoned you because there are other people, and we have given you some stuff to build off of.

 

just run it in the sql tab

 

and try to not use that concacatanation shenanigans :|

Link to comment
Share on other sites

Just tried in the database, and its returning zero rows, thats probably why.

Im totally at a loss to why this is!

The field with the username is touser, and thats the username im trying to get all the comments for. The username is in a variable I have specified.

 

any ideas mate?

Link to comment
Share on other sites

I want it to be exact with what it returns, the username that it is going for needs to be exactly the same.

 

The idea is that on user profiles, there will be comments from other users.

I have already submitted the comments, from one other to another. Now trying to get the right comments on the right profiles.

 

So the WHERE touser = username, is the most precise yeah?

But for some reason it wont return anything on the php page, only in phpmyadmin!

Link to comment
Share on other sites

ya i musta lost something along the way... i think i confused this with a search thread i was in :|

 

try making the $res=mysql_query(  THE STRING THAT WORKS IN PHPMYADMIN WITH NO concatctanation :o  );

 

then doing      $row=mysql_fetch_assoc($res);

 

then doing print_r($row);  exit();

 

and see what shows up :)

Link to comment
Share on other sites

Got it working now with the variable for the profile you are on.

 

This is what I got,

Array ( [touser] => user1 [fromuser] => user2 [comment] => blah blah  [commentdate] => 2009-07-06 19:58:18 [commentid] => 12 )

 

It only shows the first comment from each user though.

And how do i seperate each field? Do i run SELECT field each time seperately?

Thanks so much for helping

Link to comment
Share on other sites

you'll do

 


$res=mysql_query($query);

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

$touser=$row['touser'];
$fromuser=$row['fromuser'];
$comment=$row['comment'];
$commentdate=$row['commentdate'];
$commentid=$row['commentid'];

echo "TO: $touser FROM: $fromuser\n";
echo "COMMENT: $comment\n";
echo "SENT ON: $commentdate\n";
echo "ID OF: $commentid\n";

echo "<br />\n";


}

 

then for each iteration it'll update the variables from the db

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.