Hi every1,

I am new to php... From the image that i have attached you can see what i basically need... In view users.php v can see who r all the users.. and clicking on that particular user,.it has to display that particular users details.

eg: when we click user1 ---> user1 details has to be displayed.
When we click user2 --- > user2 details has to displayed...
what i have now is

$query  = "SELECT company_name, c_name, c_pass,c_email FROM company_creator";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Company Name :{$row['company_name']} <br>" .
         "name : {$row['c_name']} <br>" . 
         "password : {$row['c_pass']} <br>".
         "Emial : {$row['c_email']} <br><br>";
} 

if i click either user1 or user 2 i can see all the users details....

PLs help..
thanks :)
Tryphy

Here this will help.. i use this in my code..
This list the users. so.. Users.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("my_db");
$result = mysql_query("SELECT * FROM my_table");
while($row = mysql_fetch_array($result)) { echo"
<table width="100%" border="0">
     <tr>
          <td><a href='view_profile.php?id=".$row['id']."'>".$row['name']."</td>
     </tr>
</table>";
}
?>

And this the "view_profile.php". Basically when u click on the name, it passes the ID variable to the next page where you will use it to access the database.

<?php
mysql_connect("localhost","root","");
mysql_select_db("my_db");
$sql = "SELECT * FROM my_table WHERE id=$_GET[id]";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<table width="100%" border="0">
     <tr>
          <td>Name:</td>
          <td><?php echo ".$row['name']." ?></td>
     </tr>
     <tr>
          <td>Blah:</td>
          <td><?php ...blah?></td>
     </tr>
</table>

I like it this way, because now you can use HTML to build your stuff and then use a little bit of php code to access the rows.. I really hope this helps.

Thanks fobos...
It worked for me..

Thnks again for ur help..

Tryphy

HI fobos,

Ur code helped me a lot...Thanks..
I have another doubt is.. How do v edit particular user's details..
like, when we click edit >> it goes to a form page, where he gets the data from the database and passed in the form textbox..
In that he can edit and click Update,...Which gets updated...
I think it has to use some session...
But i havent used session b4..If u guide me with the code in this.. it wil be very good for me...and usefull.. I have read through some session examples...but i dont know how to apply with it...
Pls explain me with some codes...
Thanks a lot..
:)

Yeah, i will show you things, cause what your asking is what i already use. The thing is, im at work right now typing off my phone, so i will try to help after work..:yawn:

Ok just like i showed you where you can display it in text, now im gonna show you to put it into "<inputs>" ok?..
So this is what i first showed you...

<?php
mysql_connect("localhost","root","");
mysql_select_db("my_db");
$sql = "SELECT * FROM my_table WHERE id=$_GET[id]";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<table width="100%" border="0">
     <tr>
          <td>Name:</td>
          <td><?php echo ".$row['name']." ?></td>
     </tr>
     <tr>
          <td>Blah:</td>
          <td><?php ...blah?></td>
     </tr>
</table>

So, all this does it print out in plain text. Now im gonna add inputs.. We are gonna use the same coding structure, but add some stuff.

<body>
<?php 
// same mysql coding
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<?php echo "<input type="hidden" name="id" value="$row[id]">"; ?>
<table width="100%" border="0">
     <tr>
          <td>Name:</td>
          <td><?php echo "<input type='text' name='name' value='$row[name]'>"; ?></td>
     </tr>
     <tr>
          <td>Blah:</td>
          <td><?php ...blah?></td>
     </tr>
     <tr>
          <td width='60%' align='left'>
          <input type='submit' name='change' class='button' value='Change'></td>
     </tr>
</table>
</form>
</body>
//Now to use updating.
if(isset($_POST['change'])) {
$con = mysql_connect("localhost","root","");
if (!$con) {
     die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
mysql_query("UPDATE my_table SET 
name = '$_POST[name]', blah = '$_POST[blah]' WHERE id = '$_POST[id]'");
}
?>
</html>

I really hope this works, if it doesnt i will strip down what i have and attach it as a file so u can see.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.