Jump to content

how to get a specific row from databse


rahber

Recommended Posts

<?php
$server="localhost";
$user="root";
$database="z_db";
$password="";
$con = mysql_connect($server,$user,$password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db($database, $con);

$result = mysql_query("SELECT * FROM rahber Where id='id'");


echo "<table border='1'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Fathername</th>
<th>phone</th>
<th>dob</th>
<th>cgpa</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['FatherName'] . "</td>";
  echo "<td>" . $row['PhoneNo'] . "</td>";
  echo "<td>" . $row['Dob'] . "</td>";
  echo "<td>" . $row['CGPA'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

 

Ok i got another problem i am new to php so dont mind if i ask stupid questions

 

the code i pasted above has no errors but when i put details.php?id=1 it is not fetching the row that contains id number1

can nay one help me ?

Link to comment
https://forums.phpfreaks.com/topic/198646-how-to-get-a-specific-row-from-databse/
Share on other sites

That's because your SQL doesn't check for it.

 

$result = mysql_query("SELECT * FROM rahber Where id='id'");

 

The best way to do this is the following:

$sql = "SELECT * FROM rahber Where id='id'";
$result = mysql_query($sql);

 

That way, you can echo out the query to see if it's correct.

 

$sql = "SELECT * FROM rahber Where id='id'";
echo $sql;
$result = mysql_query($sql);

 

If you did that, you would see that you're always looking up WHERE id = 'id'.

 

Does the help?

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.