/    Sign up×
Community /Pin to ProfileBookmark

Show data with link

Dear Experts,

I have following codes

[code=php]$sql = “SELECT * from contacts order by name” ;
$select = mysqli_query($con,$sql);
$row=mysqli_num_rows($select);
//echo ($row);
while($row = mysqli_fetch_array($select))
{
echo “<tr>”;
echo “<td> <a href=’edit.php?id=”.$row[‘id’].”‘>
<img border=noborder src=images/pencil.png title=Display></a></td>”;
echo “<td align=’left’> ” . $row[“name”]. “</td>”;
echo “<td> ” . $row[“moba”]. “</td>”;
echo “<td> ” . $row[“city”]. “</td>”;
echo “<td> ” . $row[“country”] . “</td>”;
echo “</tr>”;
}
?> </tbody>
</table>
[/code]

and Edit.php has this data

[code=php]<?php
require_once(“connect.php”);
$sno =$_GET[‘id’];
$query =”SELECT * FROM contacts WHERE id = $sno “;
$result=mysqli_query($con, $query);

if ($result){

while ($row = mysqli_fetch_array($result))
{
echo $row[‘name’].”<br>”;
echo $row[‘moba’];
}
}else{
echo “no data found”;
}
?>[/code]

I press a link then related data must appear in related textboxes against selected id like shown in image

[IMG]http://i41.tinypic.com/2qdmo3m.jpg[/IMG]

Please help

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@unasAquilaDec 14.2013 — you could create an array
[code=php]
$inputs = array();
if ($result){
while ($row = mysqli_fetch_array($result)) {
$inputs['name'] = $row['name'];
$inputs['moba'] = $row['moba'];
}
}else{
echo "no data found";
}
[/code]


then use the array in your input fields

[code=php]
<form>
<input type="text" name="name" value="<?php echo isset($inputs['name']) ? $inputs['name'] : '' ?>" >
<input type="text" name="moba" value="<?php echo isset($inputs['moba']) ? $inputs['moba'] : '' ?>" >
</form>
[/code]


or your could set session vars

[code=php]
session_start();
if ($result){
while ($row = mysqli_fetch_array($result)) {
$_SESSION['name'] = $row['name'];
$_SESSION['moba'] = $row['moba'];
}
}else{
echo "no data found";
}
[/code]


then use the set session vars like so.

[code=php]
<form>
<input type="text" name="name" value="<?php echo isset($_SESSION['name']) ? $_SESSION['name'] : '' ?>" >
<input type="text" name="moba" value="<?php echo isset($_SESSION['moba']) ? $_SESSION['moba'] : '' ?>" >
</form>
[/code]


this should give you an idea on how to do what you need.
×

Success!

Help @tqmd1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...