Simple question about PHP MYSQL: retrieving data from a MYSQL database?

Ruraga

New member
I'm a newbie to PHP MYSQL. I can now retrieve data from a mysql table and print it on a webpage. But I am having a problem displaying multiple (selected) values.

I have a table in a mysql database in which there are three fields: userid, date and feedback. id is primary key.

there are ten entries by 3 people with three different id; that means there are only three userids in ten entries.

I made a PHP login script already and im working on it. A user with id 5 is logged in, which is stored in a variable 'loginid'. I want the logged in user (with user id 5) to be able to see all the feedbacks he has given till date. I need to list the multiple values in a table.

After connecting to the database, to select the table, I used the following lines:

-------------------------------
<?php

$query = mysql_query("select * from tablename where $userid = '$_SESSION['loginid']");

$num=mysql_num_rows($query);

mysql_close();

?>
--------------------------------

That is supposed to select the values in the database only of the current user (with loginid=5) and also count the number of rows and list them in $num.
Now I used these following lines to populate the list. Suppose I started table already and closed table at last (i've excluded those tags)

-------------------------------
<?php
$i=0;

$f1=mysql_result($result,$i,"date");
$f2=mysql_result($result,$i,"feedback");

while ($i < $num)
{

?>

<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>

</tr>

<?php
$i++;
}
?>
-----------------------------------

My Question: I get 2 errors.

mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home1/....../listfeedbacks.php on line ...

mysql_result(): supplied argument is not a valid MySQL result resource in /home1/......./listfeedbacks.php on line ...

What is the possible problem and the solution? I guess the bug is in the selection of database (the first query), ir is it not? Any ideas would be great help. Thanks.
P.S There IS a single quote (') in the query. That isn't the problem.
 
Back
Top