Hi geeks,
I am working on a query string but I am kinda stuck with the code, I guess this is so cos am a PHP beginner. I want my script to display members list from a table in my db and attach a hyperlink to it so that when a user clicks on the link, it takes him to the full details of that member. So far, I have been able to retrieve data from db and attached links but when I click on the link,it just adds a member ID to the query string and it does not take u to page with full member details. What I have wirtten so far is shown below:

<?php
    //connection.php
      
    $conn = mysql_connect($host, $user, $pass);
    $selDB = mysql_select_db($db);
    $sql = "select count(*) from info";
    $result = mysql_query($sql);
    $row = mysql_fetch_row($result);
    $numRows = $row[0];
    
    $sql = "select * from info";
    $result = mysql_query($sql);
    while($row = mysql_fetch_assoc($result)){ ?>
     <table>
     <td><?php echo stripslashes($row['name']). " ";?><a href="<?php echo $_SERVER['PHP_SELF']?>?id=<?php echo $row['id'];?>">[View Details]</a>
      </td>
      </tr>            
          
<?php } ?>

Guys please help me out.

Recommended Answers

All 2 Replies

Why are you echoing "<table>" in the loop this will produce a very strange HTML. Put it outside the loop.

Member Avatar for rajarajan2017
if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table cellpadding=10 border=1>"; 
    while($row = mysql_fetch_row($result)) { 
        echo "<tr>"; 
        echo "<td>".$row[0]."</td>"; 
        echo "<td>" . $row[1]."</td>"; 
        echo "<td>".$row[2]."</td>"; 
        echo "</tr>"; 
    } 
    echo "</table>"; 
} 
else { 
    // no 
    // print status message 
    echo "No rows found!"; 
}

Table things should be used like the above code

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.