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?

u have to store the results in an array

 


$res=mysql_query("SELECT * FROM table WHERE 1");

$row=mysql_fetch_assoc($res);

then u can go off the table name or #

$username=$row[1];

or

$username=$row['username'];

 

 

perhaps check out:

 

http://www.w3schools.com/SQl/default.asp

 

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];

?>

$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?

$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.

 

 

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 :|

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?

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!

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 :)

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

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

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.