rahber Posted April 15, 2010 Share Posted April 15, 2010 <?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 More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 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? Link to comment https://forums.phpfreaks.com/topic/198646-how-to-get-a-specific-row-from-databse/#findComment-1042434 Share on other sites More sharing options...
rahber Posted April 15, 2010 Author Share Posted April 15, 2010 Oh thanks for the help but i just figured out an other way $id=$id=$_GET['id']; mysql_query("SELECT * FROM rahber Where id='$id'"); Thanks the problem is solved Link to comment https://forums.phpfreaks.com/topic/198646-how-to-get-a-specific-row-from-databse/#findComment-1042436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.